]> mj.ucw.cz Git - libucw.git/commitdiff
Logging: Precise timestamps and syslog PID flag are now configurable.
authorMartin Mares <mj@ucw.cz>
Mon, 16 Feb 2009 22:55:44 +0000 (23:55 +0100)
committerMartin Mares <mj@ucw.cz>
Mon, 16 Feb 2009 22:55:44 +0000 (23:55 +0100)
cf/libucw
ucw/log-conf.c

index d525f558b67fd4f9bd763735eb76ef044c54fe92..00dba877ade070ee764450c38f3cbe0e78ab92df 100644 (file)
--- a/cf/libucw
+++ b/cf/libucw
@@ -185,11 +185,13 @@ Stream {
 Stream {
        Name            logfile2
        FileName        log/test2
+       Microseconds    1
 }
 
 Stream {
        Name            syslog
        SyslogFacility  user
+       SyslogPID       1
 }
 
 Stream {
index 9eea204eb0043fa9cf32a594faaf13ff025b9296..f811a5865acdd6dd151965db921cb634d7df9980 100644 (file)
@@ -21,6 +21,8 @@ struct stream_config {
   char *file_name;
   char *syslog_facility;
   clist substreams;                    // simple_list of names
+  int microseconds;                    // Enable logging of precise timestamps
+  int syslog_pids;
   struct log_stream *ls;
   int mark;                            // Used temporarily in log_config_commit()
 };
@@ -34,6 +36,8 @@ stream_commit(void *ptr)
     return "Both FileName and SyslogFacility selected";
   if (c->syslog_facility && !log_syslog_facility_exists(c->syslog_facility))
     return cf_printf("SyslogFacility `%s' is not recognized", c->syslog_facility);
+  if (c->syslog_facility && c->microseconds)
+    return "Syslog streams do not support microsecond precision";
   return NULL;
 }
 
@@ -46,6 +50,8 @@ static struct cf_section stream_config = {
     CF_STRING("FileName", P(file_name)),
     CF_STRING("SyslogFacility", P(syslog_facility)),
     CF_LIST("Substream", P(substreams), &cf_string_list_config),
+    CF_INT("Microseconds", P(microseconds)),
+    CF_INT("SyslogPID", P(syslog_pids)),
 #undef P
     CF_END
   }
@@ -136,13 +142,16 @@ do_new_configured(struct stream_config *c)
   if (c->file_name)
     ls = log_new_file(c->file_name);
   else if (c->syslog_facility)
-    ls = log_new_syslog(c->syslog_facility, 0);                // FIXME: Logging of PID
+    ls = log_new_syslog(c->syslog_facility, (c->syslog_pids ? LOG_PID : 0));
   else
     ls = log_new_stream(sizeof(*ls));
 
   CLIST_FOR_EACH(simp_node *, s, c->substreams)
     log_add_substream(ls, do_new_configured(stream_find(s->s)));
 
+  if (c->microseconds)
+    ls->msgfmt |= LSFMT_USEC;
+
   c->ls = ls;
   return ls;
 }