]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/log-conf.c
Logging: Adapted the `logger' utility to the new numbering of levels.
[libucw.git] / ucw / log-conf.c
index f811a5865acdd6dd151965db921cb634d7df9980..6a92c20e157ecaabe6c00c36ab745b9266ff85ff 100644 (file)
@@ -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;
 
@@ -167,6 +187,16 @@ log_new_configured(const char *name)
   return do_new_configured(c);
 }
 
+void
+log_configured(const char *name)
+{
+  struct log_stream *ls = log_new_configured(name);
+  struct log_stream *def = log_stream_by_flags(0);
+  log_rm_substream(def, NULL);
+  log_add_substream(def, ls);
+  log_close_stream(ls);
+}
+
 #ifdef TEST
 
 #include "ucw/getopt.h"