From 7ab2c0e4a53846a060e1707a2462a824e7245a7b Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 13 Oct 2010 17:50:22 +0200 Subject: [PATCH] Add logbanner directive --- chrony.texi | 11 +++++++++++ conf.c | 21 +++++++++++++++++++++ conf.h | 1 + logging.c | 4 +++- 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/chrony.texi b/chrony.texi index f86a0ac..26320ce 100644 --- a/chrony.texi +++ b/chrony.texi @@ -1185,6 +1185,7 @@ directives can occur in any order in the file. * linux_freq_scale directive:: Define a non-standard value to compensate the kernel frequency bias * local directive:: Allow unsynchronised machine to act as server * log directive:: Make daemon log certain sets of information +* logbanner directive:: Specify how often is banner written to log files * logchange directive:: Generate syslog messages if large offsets occur * logdir directive:: Specify directory for logging * mailonchange directive:: Send email if a clock correction above a threshold occurs @@ -2108,6 +2109,16 @@ A banner is periodically written to the log file to indicate the meanings of the columns. @c }}} @c }}} +@c {{{ logbanner +@node logbanner directive +@subsection logbanner +A banner is periodically written to the log files enabled by the +@code{log} directive to indicate the meanings of the columns. + +The @code{logbanner} directive specifies after how many entries in the +log file should be the banner written. The default is 32, and 0 can be +used to disable it entirely. +@c }}} @c {{{ logchange @node logchange directive @subsection logchange diff --git a/conf.c b/conf.c index 5bfd326..e4ed75a 100644 --- a/conf.c +++ b/conf.c @@ -74,6 +74,7 @@ static void parse_dumponexit(const char *); static void parse_keyfile(const char *); static void parse_rtcfile(const char *); static void parse_log(const char *); +static void parse_logbanner(const char *); static void parse_logdir(const char *); static void parse_maxupdateskew(const char *); static void parse_peer(const char *); @@ -129,6 +130,7 @@ static int do_log_rtc = 0; static int do_log_refclocks = 0; static int do_log_tempcomp = 0; static int do_dump_on_exit = 0; +static int log_banner = 32; static char *logdir = "."; static char *dumpdir = "."; @@ -224,6 +226,7 @@ static const Command commands[] = { {"driftfile", 9, parse_driftfile}, {"keyfile", 7, parse_keyfile}, {"rtcfile", 7, parse_rtcfile}, + {"logbanner", 9, parse_logbanner}, {"logdir", 6, parse_logdir}, {"log", 3, parse_log}, {"dumponexit", 10, parse_dumponexit}, @@ -645,6 +648,16 @@ parse_rtcdevice(const char *line) /* ================================================== */ +static void +parse_logbanner(const char *line) +{ + if (sscanf(line, "%d", &log_banner) != 1) { + LOG(LOGS_WARN, LOGF_Configure, "Could not read logbanner number at line %d in file", line_number); + } +} + +/* ================================================== */ + static void parse_logdir(const char *line) { @@ -1274,6 +1287,14 @@ CNF_GetDriftFile(void) /* ================================================== */ +int +CNF_GetLogBanner(void) +{ + return log_banner; +} + +/* ================================================== */ + char * CNF_GetLogDir(void) { diff --git a/conf.h b/conf.h index cf8788b..9ccef77 100644 --- a/conf.h +++ b/conf.h @@ -48,6 +48,7 @@ extern unsigned short CNF_GetNTPPort(void); extern char *CNF_GetDriftFile(void); extern char *CNF_GetLogDir(void); extern char *CNF_GetDumpDir(void); +extern int CNF_GetLogBanner(void); extern int CNF_GetLogMeasurements(void); extern int CNF_GetLogStatistics(void); extern int CNF_GetLogTracking(void); diff --git a/logging.c b/logging.c index 61cb973..591b552 100644 --- a/logging.c +++ b/logging.c @@ -233,6 +233,7 @@ void LOG_FileWrite(LOG_FileID id, const char *format, ...) { va_list other_args; + int banner; if (id < 0 || id >= n_filelogs || !logfiles[id].name) return; @@ -249,7 +250,8 @@ LOG_FileWrite(LOG_FileID id, const char *format, ...) } } - if (logfiles[id].writes++ % 32 == 0) { + banner = CNF_GetLogBanner(); + if (banner && logfiles[id].writes++ % banner == 0) { char bannerline[256]; int i, bannerlen;