summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
67cb641)
The function receives the values given to the --log-color option as
a char * array, which is the type that gengetopt provides for the
arguments to string options which may be given multiple times.
This patch gets get rid of this implementation detail. The function no
longer takes the arguments to --log-color at all and applications now
must call daemon_set_log_color_or_die() themselves to set user-defined
per-loglevel colors.
To make this work, we let daemon_init_colors_or_die() return a
boolean which indicates whether color mode should be enabled, and
daemon_set_log_color_or_die() is made public. The two users of this
API, para_server and para_audiod, are adjusted accordingly.
daemon_set_priority(conf.priority_arg);
daemon_drop_privileges_or_die(conf.user_arg, conf.group_arg);
parse_config_or_die();
daemon_set_priority(conf.priority_arg);
daemon_drop_privileges_or_die(conf.user_arg, conf.group_arg);
parse_config_or_die();
- daemon_init_colors_or_die(conf.color_arg, color_arg_auto, color_arg_no,
- conf.logfile_given, conf.log_color_arg, conf.log_color_given);
+ if (daemon_init_colors_or_die(conf.color_arg, color_arg_auto, color_arg_no,
+ conf.logfile_given)) {
+ for (i = 0; i < conf.log_color_given; i++)
+ daemon_set_log_color_or_die(conf.log_color_arg[i]);
+ }
init_random_seed_or_die();
daemon_set_flag(DF_LOG_TIME);
daemon_set_flag(DF_LOG_HOSTNAME);
init_random_seed_or_die();
daemon_set_flag(DF_LOG_TIME);
daemon_set_flag(DF_LOG_HOSTNAME);
color_parse_or_die(default_log_colors[i], me->log_colors[i]);
}
color_parse_or_die(default_log_colors[i], me->log_colors[i]);
}
* Set the color for one loglevel.
*
* Set the color for one loglevel.
*
- * arg must be of the form "ll:[fg [bg]] [attr]".
+ * \param arg Must be of the form "ll:[fg [bg]] [attr]".
-static void daemon_set_log_color_or_die(char const *arg)
+void daemon_set_log_color_or_die(const char *arg)
{
char *p = strchr(arg, ':');
int ret, ll;
{
char *p = strchr(arg, ':');
int ret, ll;
* \param color_arg_auto The value for automatic color detection.
* \param color_arg_no The value to disable colored log messages.
* \param logfile_given In auto mode colors are disabled if this value is true.
* \param color_arg_auto The value for automatic color detection.
* \param color_arg_no The value to disable colored log messages.
* \param logfile_given In auto mode colors are disabled if this value is true.
- * \param log_color_argv Color specifiers given to --log-color.
- * \param argc Number of color specifiers in \a log_color_argv.
- * If \a color_arg equals \a color_arg_no, color mode is disabled, i.e., calls
- * to \a para_log() will not produce colored output. If \a color_arg == \a
- * color_arg_auto, the function autodetects whether to activate colors.
- * Otherwise color mode is enabled.
+ * If color_arg equals color_arg_no, color mode is disabled. That is, calls to
+ * para_log() will not produce colored output. If color_arg equals
+ * color_arg_auto, the function detects automatically whether to activate
+ * colors. Otherwise color mode is enabled.
+ *
+ * If color mode is to be enabled, the default colors are set for each
+ * loglevel. They can be overwritten by calling daemon_set_log_color_or_die().
- * If color mode is to be enabled, the strings in \a log_color_argv are parsed
- * and the color scheme is updated accordingly. For each loglevel, the default
- * colors apply if there is no log_color_argv for this loglevel.
+ * \return Whether colors have been enabled by the function.
-void daemon_init_colors_or_die(int color_arg, int color_arg_auto,
- int color_arg_no, bool logfile_given, char **log_color_argv,
- int argc)
+bool daemon_init_colors_or_die(int color_arg, int color_arg_auto,
+ int color_arg_no, bool logfile_given)
if (color_arg == color_arg_no)
if (color_arg == color_arg_no)
if (color_arg == color_arg_auto) {
if (logfile_given)
if (color_arg == color_arg_auto) {
if (logfile_given)
if (!isatty(STDERR_FILENO))
if (!isatty(STDERR_FILENO))
}
daemon_set_flag(DF_COLOR_LOG);
daemon_set_default_log_colors();
}
daemon_set_flag(DF_COLOR_LOG);
daemon_set_default_log_colors();
- for (i = 0; i < argc; i++)
- daemon_set_log_color_or_die(log_color_argv[i]);
void daemon_set_logfile(const char *logfile_name);
void daemon_set_flag(unsigned flag);
void daemon_set_loglevel(const char *loglevel);
void daemon_set_logfile(const char *logfile_name);
void daemon_set_flag(unsigned flag);
void daemon_set_loglevel(const char *loglevel);
-void daemon_init_colors_or_die(int color_arg, int color_arg_auto,
- int color_arg_no, bool logfile_given, char **log_color_argv,
- int argc);
+bool daemon_init_colors_or_die(int color_arg, int color_arg_auto,
+ int color_arg_no, bool logfile_given);
+void daemon_set_log_color_or_die(const char *arg);
__printf_2_3 void daemon_log(int ll, const char* fmt,...);
/** Daemon log configuration flags. */
__printf_2_3 void daemon_log(int ll, const char* fmt,...);
/** Daemon log configuration flags. */
daemon_open_log_or_die();
}
daemon_open_log_or_die();
}
- daemon_init_colors_or_die(conf.color_arg, color_arg_auto, color_arg_no,
- conf.logfile_given, conf.log_color_arg, conf.log_color_given);
+ if (daemon_init_colors_or_die(conf.color_arg, color_arg_auto, color_arg_no,
+ conf.logfile_given)) {
+ int i;
+ for (i = 0; i < conf.log_color_given; i++)
+ daemon_set_log_color_or_die(conf.log_color_arg[i]);
+ }
daemon_set_flag(DF_LOG_PID);
daemon_set_flag(DF_LOG_LL);
daemon_set_flag(DF_LOG_TIME);
daemon_set_flag(DF_LOG_PID);
daemon_set_flag(DF_LOG_LL);
daemon_set_flag(DF_LOG_TIME);