]> mj.ucw.cz Git - libucw.git/commitdiff
Logging: Following streams by stderr is now configurable.
authorMartin Mares <mj@ucw.cz>
Sat, 21 Feb 2009 21:22:49 +0000 (22:22 +0100)
committerMartin Mares <mj@ucw.cz>
Sat, 21 Feb 2009 21:22:49 +0000 (22:22 +0100)
cf/libucw
ucw/log-conf-test.cf
ucw/log-conf.c

index 4f0f81b1f7d1d038de87795a0ba04de1d61bd697..b92efad696c4b3619fc107a80728eadf1d8535f5 100644 (file)
--- a/cf/libucw
+++ b/cf/libucw
@@ -219,6 +219,9 @@ Logging {
 #      # guaranteed to be complete. (default: 0)
 #      ErrorsFatal     1
 #
+#      # Let stderr of the program point to this file-based log_stream (default: 0)
+#      StdErrFollows   1
+#
 #      # Some events are logworthy, but they could happen too frequently and flood the log.
 #      # You can avoid the flooding by setting up a rate limiter for a specific subset of
 #      # message types. If more limiters match the type of a message, only the last one applies.
index 3ceaaf34527d5676322dcef1c5861cb722436467..f1d2b20a9f1947d96fb4c8eecbc0647e3c09100f 100644 (file)
@@ -5,6 +5,7 @@ Logging {
 Stream {
        Name            logfile
        FileName        log/test
+       StdErrFollows   1
        Limit { Rate 100 }
 }
 
index 15be98e8d0df313232bf79cfea80f533d00f949d..d0afece0fb7e650ebe9e6f33157bff9c6dff00dd 100644 (file)
@@ -35,6 +35,7 @@ struct stream_config {
   int show_types;
   int syslog_pids;
   int errors_fatal;
+  int stderr_follows;
   struct log_stream *ls;
   int mark;                            // Used temporarily in log_config_commit()
 };
@@ -60,12 +61,17 @@ stream_commit(void *ptr)
 {
   struct stream_config *c = ptr;
 
-  if (c->file_name && c->syslog_facility)
-    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";
+  if (c->syslog_facility)
+    {
+      if (!log_syslog_facility_exists(c->syslog_facility))
+       return cf_printf("SyslogFacility `%s' is not recognized", c->syslog_facility);
+      if (c->file_name)
+       return "Both FileName and SyslogFacility selected";
+      if (c->microseconds)
+       return "Syslog streams do not support microsecond precision";
+    }
+  if (c->stderr_follows && !c->file_name)
+    return "StdErrFollows requires a file-based stream";
   return NULL;
 }
 
@@ -105,6 +111,7 @@ static struct cf_section stream_config = {
     CF_INT("ShowTypes", P(show_types)),
     CF_INT("SyslogPID", P(syslog_pids)),
     CF_INT("ErrorsFatal", P(errors_fatal)),
+    CF_INT("StdErrFollows", P(stderr_follows)),
 #undef P
     CF_END
   }
@@ -285,7 +292,7 @@ do_new_configured(struct stream_config *c)
     return c->ls;
 
   if (c->file_name)
-    ls = log_new_file(c->file_name, 0);
+    ls = log_new_file(c->file_name, (c->stderr_follows ? FF_FD2_FOLLOWS : 0));
   else if (c->syslog_facility)
     ls = log_new_syslog(c->syslog_facility, (c->syslog_pids ? LOG_PID : 0));
   else
@@ -350,6 +357,7 @@ int main(int argc, char **argv)
       msg(L_INFO | ls->regnum | type, "Hello, universe!");
       usleep(200000);
     }
+  fprintf(stderr, "Alas, this was printed to stderr.\n");
 
   log_close_all();
   return 0;