+ * Activate default log colors.
+ *
+ * This should be called early if color support is wanted.
+ */
+void daemon_set_default_log_colors(void)
+{
+ int i;
+ static const char *default_log_colors[NUM_LOGLEVELS] = {
+ [LL_DEBUG] = "normal",
+ [LL_INFO] = "normal",
+ [LL_NOTICE] = "normal",
+ [LL_WARNING] = "yellow",
+ [LL_ERROR] = "red",
+ [LL_CRIT] = "magenta bold",
+ [LL_EMERG] = "red bold",
+ };
+ for (i = 0; i < NUM_LOGLEVELS; i++) {
+ int ret = color_parse(default_log_colors[i], me->log_colors[i]);
+ assert(ret >= 0);
+ }
+}
+
+/**
+ * Set the color for one loglevel.
+ *
+ * \param arg The loglevel/color specifier.
+ *
+ * \a arg must be of the form "ll:[fg [bg]] [attr]".
+ *
+ * \return 1 On success, -1 on errors.
+ */
+int daemon_set_log_color(char const *arg)
+{
+ char *p = strchr(arg, ':');
+ int ret, ll;
+
+ if (!p)
+ goto err;
+ ret = get_loglevel_by_name(arg);
+ if (ret < 0)
+ goto err;
+ ll = ret;
+ p++;
+ ret = color_parse(p, me->log_colors[ll]);
+ if (ret < 0)
+ goto err;
+ return 1;
+err:
+ PARA_ERROR_LOG("%s: color syntax error\n", arg);
+ return -1;
+
+}
+
+/**
+ * Init or change the name of the log file.
+ *
+ * \param logfile_name The full path of the logfile.
+ */
+void daemon_set_logfile(char *logfile_name)
+{
+ free(me->logfile_name);
+ me->logfile_name = NULL;
+ if (logfile_name)
+ me->logfile_name = para_strdup(logfile_name);
+}
+
+/**
+ * Suppress log messages with severity lower than the given loglevel.
+ *
+ * \param loglevel The smallest level that should be logged.
+ */
+void daemon_set_loglevel(char *loglevel)
+{
+ int ret = get_loglevel_by_name(loglevel);
+
+ assert(ret >= 0);
+ me->loglevel = ret;
+}
+
+/**
+ * Set one of the daemon config flags.
+ *
+ * \param flag The flag to set.
+ *
+ * \sa \ref daemon_flags.
+ */
+void daemon_set_flag(unsigned flag)
+{
+ me->flags |= flag;
+}
+
+/**
+ * Clear one of the daemon config flags.
+ *
+ * \param flag The flag to clear.
+ *
+ * \sa \ref daemon_flags.
+ */
+void daemon_clear_flag(unsigned flag)
+{
+ me->flags &= ~flag;
+}
+
+static bool daemon_test_flag(unsigned flag)
+{
+ return me->flags & flag;
+}
+
+/**
+ * Do the usual stuff to become a daemon.