From 72b478fbc7b5ec664d06ab18181f96c1486b2e5a Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Thu, 19 Feb 2009 17:22:44 +0100 Subject: [PATCH] Logging: Let the log level mask be configurable. --- cf/libucw | 1 + ucw/lib.h | 2 ++ ucw/log-conf.c | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/cf/libucw b/cf/libucw index 00dba877..a6f19919 100644 --- a/cf/libucw +++ b/cf/libucw @@ -186,6 +186,7 @@ Stream { Name logfile2 FileName log/test2 Microseconds 1 + Levels:reset warn error } Stream { diff --git a/ucw/lib.h b/ucw/lib.h index 0ec02192..5167e24e 100644 --- a/ucw/lib.h +++ b/ucw/lib.h @@ -102,6 +102,8 @@ enum log_levels { /** The available log levels to pass to msg() and friends. * L_FATAL, // '!' - Fatal error }; +#define LOG_LEVEL_NAMES P(DEBUG) P(INFO) P(WARN) P(ERROR) P(INFO_R) P(WARN_R) P(ERROR_R) P(FATAL) + #define L_SIGHANDLER 0x80000000 /** Avoid operations that are unsafe in signal handlers **/ /** diff --git a/ucw/log-conf.c b/ucw/log-conf.c index 47feceae..6a92c20e 100644 --- a/ucw/log-conf.c +++ b/ucw/log-conf.c @@ -20,6 +20,7 @@ struct stream_config { char *name; char *file_name; char *syslog_facility; + u32 levels; clist substreams; // simple_list of names int microseconds; // Enable logging of precise timestamps int syslog_pids; @@ -27,6 +28,15 @@ struct stream_config { int mark; // Used temporarily in log_config_commit() }; +static char * +stream_init(void *ptr) +{ + struct stream_config *c = ptr; + + c->levels = ~0U; + return NULL; +} + static char * stream_commit(void *ptr) { @@ -41,14 +51,23 @@ stream_commit(void *ptr) return NULL; } +static const char * const level_names[] = { +#define P(x) #x, + LOG_LEVEL_NAMES +#undef P + NULL +}; + static struct cf_section stream_config = { CF_TYPE(struct stream_config), + CF_INIT(stream_init), CF_COMMIT(stream_commit), CF_ITEMS { #define P(x) PTR_TO(struct stream_config, x) CF_STRING("Name", P(name)), CF_STRING("FileName", P(file_name)), CF_STRING("SyslogFacility", P(syslog_facility)), + CF_BITMAP_LOOKUP("Levels", P(levels), level_names), CF_LIST("Substream", P(substreams), &cf_string_list_config), CF_INT("Microseconds", P(microseconds)), CF_INT("SyslogPID", P(syslog_pids)), @@ -149,6 +168,7 @@ do_new_configured(struct stream_config *c) CLIST_FOR_EACH(simp_node *, s, c->substreams) log_add_substream(ls, do_new_configured(stream_find(s->s))); + ls->levels = c->levels; if (c->microseconds) ls->msgfmt |= LSFMT_USEC; -- 2.39.2