[patch] Add support for logrotate and timestamps

Jim Meyering jim at meyering.net
Tue Aug 2 13:43:24 UTC 2011


Pete Zaitcev wrote:
> This patch overhauls the logging system, in order to satisfy two requests:
> 1. to support logrotate, and 2. to add timestamps.
>
> For the second one, we establish a preferred logging facility, represented
> by log_msg() and embark on converting the code to it. For now we only
> do it to easier cases, where error() does not exit or prints error
> messages for errno values. The bug requestor, Wes, says that having
> timestamps "often enough" is good enough. We not need to do anything crazy
> like re-piping standard error through a timestamping routine.
>
> For the first request, the daemon has to be able to reopen the log, which
> is not possible if it simply dumps everything to standard error.
> Note that due to the desire to capture the library output and the
> conversion to log_msg() being not complete, we do it in a tricky way by
> substituting standard output and standard error file descriptors,
> instead of simply calling freopen().
>
> Most of the logging.[hc] was written by Mark McLoughlin.

Thanks for the adjustments.
They look fine, but there are two syntax-check failures.
These additional changes avoid those:
  - change syntax of log function declarations so that the
      tight-scope check can find them.
  - list logging.c in POTFILES.in, for translations

diff --git a/logging.h b/logging.h
index 07d771d..fb82515 100644
--- a/logging.h
+++ b/logging.h
@@ -25,10 +25,10 @@ enum log_level {
 	IW_LOG_DEBUG
 };

-void log_msg(enum log_level level, const char *fmt, ...)
+extern void log_msg (enum log_level level, const char *fmt, ...)
 	__attribute__ ((format (printf, 2, 3)));
-void log_init(enum log_level level, const char *path);
-void log_check(void);
+extern void log_init (enum log_level level, const char *path);
+extern void log_check (void);

 #define DPRINTF(fmt, args...) log_msg(IW_LOG_DEBUG, fmt, ##args)

diff --git a/po/POTFILES.in b/po/POTFILES.in
index 24f87a8..2dbb93a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -10,6 +10,7 @@ lib/set-mode-acl.c
 lib/version-etc.c
 lib/xalloc-die.c
 lib/xstrtol-error.c
+logging.c
 qparser.y
 replica.c
 rest.c


More information about the iwhd-devel mailing list