]> mj.ucw.cz Git - libucw.git/commitdiff
libucw: Implemented Loging.Stream.FileDesc.
authorPavel Charvat <pchar@ucw.cz>
Thu, 18 Feb 2010 15:12:15 +0000 (16:12 +0100)
committerPavel Charvat <pchar@ucw.cz>
Thu, 18 Feb 2010 15:12:15 +0000 (16:12 +0100)
cf/libucw
ucw/log-conf.c

index 7c061ec4056c9ba6da415f898aafbd7ad3e5a41c..e6318c25b86eabcb8258c9f73ccde04ac63f05fd 100644 (file)
--- a/cf/libucw
+++ b/cf/libucw
@@ -187,6 +187,9 @@ Logging {
 #      # Escape sequences for current date and time as described in strftime(3) can be used.
 #      FileName        log/test-%Y%m%d
 #
+#      # If you need to log to stderr or another already opened descriptor, you can specify its number.
+#      FileDesc        2
+#
 #      # Instead of a file, a syslog facility can be specified. See syslog(3) for an explanation.
 #      SyslogFacility  daemon
 #
index d0afece0fb7e650ebe9e6f33157bff9c6dff00dd..26d7d5c46d106eb8bb136b0275e9a8c959c9e44e 100644 (file)
@@ -26,6 +26,7 @@ struct stream_config {
   cnode n;
   char *name;
   char *file_name;
+  int file_desc;
   char *syslog_facility;
   u32 levels;
   clist types;                         // simple_list of names
@@ -53,6 +54,7 @@ stream_init(void *ptr)
   struct stream_config *c = ptr;
 
   c->levels = ~0U;
+  c->file_desc = -1;
   return NULL;
 }
 
@@ -102,6 +104,7 @@ static struct cf_section stream_config = {
 #define P(x) PTR_TO(struct stream_config, x)
     CF_STRING("Name", P(name)),
     CF_STRING("FileName", P(file_name)),
+    CF_INT("FileDesc", P(file_desc)),
     CF_STRING("SyslogFacility", P(syslog_facility)),
     CF_BITMAP_LOOKUP("Levels", P(levels), level_names),
     CF_LIST("Types", P(types), &cf_string_list_config),
@@ -293,6 +296,8 @@ do_new_configured(struct stream_config *c)
 
   if (c->file_name)
     ls = log_new_file(c->file_name, (c->stderr_follows ? FF_FD2_FOLLOWS : 0));
+  else if (c->file_desc >= 0)
+    ls = log_new_fd(c->file_desc, (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