]> mj.ucw.cz Git - libucw.git/commitdiff
Logging: Type-based filters and logging of type names are configurable.
authorMartin Mares <mj@ucw.cz>
Thu, 19 Feb 2009 18:56:06 +0000 (19:56 +0100)
committerMartin Mares <mj@ucw.cz>
Thu, 19 Feb 2009 18:56:06 +0000 (19:56 +0100)
cf/libucw
ucw/log-conf.c

index effeb25a2fdfba14c75663922ec2265fe47ce5e2..54bb667913fe7ef29c00deaec1233a002bad940a 100644 (file)
--- 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 {
index bea6ad0c1d4ccb0f2ef7095f1f3ac6050a1b5ff5..b6fbbb509325fc85f9e022dce72deb8ce3624af2 100644 (file)
@@ -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;