From 369e3caec4caee65ae4c16d5c04b0f43a50a3150 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Thu, 19 Feb 2009 19:56:06 +0100 Subject: [PATCH] Logging: Type-based filters and logging of type names are configurable. --- cf/libucw | 4 +++- ucw/log-conf.c | 28 +++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/cf/libucw b/cf/libucw index effeb25a..54bb6679 100644 --- a/cf/libucw +++ b/cf/libucw @@ -186,8 +186,10 @@ Stream { Name logfile2 FileName log/test2 Microseconds 1 - Levels:reset warn error + Levels:reset info warn error + Types:reset default foo ErrorsFatal 1 + ShowTypes 1 } Stream { diff --git a/ucw/log-conf.c b/ucw/log-conf.c index bea6ad0c..b6fbbb50 100644 --- a/ucw/log-conf.c +++ b/ucw/log-conf.c @@ -21,8 +21,10 @@ struct stream_config { char *file_name; char *syslog_facility; u32 levels; + clist types; // simple_list of names clist substreams; // simple_list of names int microseconds; // Enable logging of precise timestamps + int show_types; int syslog_pids; int errors_fatal; struct log_stream *ls; @@ -69,8 +71,10 @@ static struct cf_section stream_config = { CF_STRING("FileName", P(file_name)), CF_STRING("SyslogFacility", P(syslog_facility)), CF_BITMAP_LOOKUP("Levels", P(levels), level_names), + CF_LIST("Types", P(types), &cf_string_list_config), CF_LIST("Substream", P(substreams), &cf_string_list_config), CF_INT("Microseconds", P(microseconds)), + CF_INT("ShowTypes", P(show_types)), CF_INT("SyslogPID", P(syslog_pids)), CF_INT("ErrorsFatal", P(errors_fatal)), #undef P @@ -173,9 +177,30 @@ do_new_configured(struct stream_config *c) ls->levels = c->levels; if (c->microseconds) ls->msgfmt |= LSFMT_USEC; + if (c->show_types) + ls->msgfmt |= LSFMT_TYPE; if (c->errors_fatal) ls->stream_flags |= LSFLAG_ERR_IS_FATAL; + if (!clist_empty(&c->types)) + { + ls->types = 0; + CLIST_FOR_EACH(simp_node *, s, c->types) + if (!strcmp(s->s, "all")) + ls->types = ~0U; + else + { + /* + * We intentionally ignore unknown types as not all types are known + * to all programs sharing a common configuration file. This is also + * the reason why Types is a list and not a bitmap. + */ + int type = log_find_type(s->s); + if (type >= 0) + ls->types |= 1 << LS_GET_TYPE(type); + } + } + c->ls = ls; return ls; } @@ -212,8 +237,9 @@ int main(int argc, char **argv) while ((c = cf_getopt(argc, argv, CF_SHORT_OPTS, CF_NO_LONG_OPTS, NULL)) >= 0) die("No options here."); + int type = log_register_type("foo"); struct log_stream *ls = log_new_configured("combined"); - msg(L_INFO | ls->regnum, "Hello, universe!"); + msg(L_INFO | ls->regnum | type, "Hello, universe!"); log_close_all(); return 0; -- 2.39.5