[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: Re: [patch] new option for syslogd to include year in log timestamps
From: Joshua Judson Rosen <jrosen () harvestai ! com>
Date: 2012-03-28 15:53:51
Message-ID: 4F73340F.2010404 () harvestai ! com
[Download RAW message or body]
On 22/03/12 14:49, Joshua Judson Rosen wrote:
> Attached is a patch adding a config-option to have syslogd include the year
> in the timestamps that it writes. I've found that this is useful for
> long-running systems that don't have a sysadmin watching them most of
> the time. Probably other people would also find it useful.
Uh, OK--that patch was really wrong (if something seems too easy..., maybe it is).
Here's a version that takes into account the fact that libc's syslog() generates
its own timestamps, and overrides them if they're present in incoming messages.
--
"Don't be afraid to ask (λf.((λx.xx) (λr.f(rr))))."
["syslog-full-timestamps.patch" (text/x-patch)]
diff --git a/sysklogd/Config.src b/sysklogd/Config.src
index b7a494e..2e467ff 100644
--- a/sysklogd/Config.src
+++ b/sysklogd/Config.src
@@ -22,6 +22,17 @@ config SYSLOGD
wrong. And something almost always will go wrong if
you wait long enough....
+config FEATURE_SYSLOG_TIMESTAMP_YEAR
+ bool "Include year in syslog timestamps"
+ default n
+ help
+ Timestamps in system logs traditionally do not include
+ the year, but this can be useful for some long-running
+ systems where logs are checked infrequently.
+ Note that this causes syslogd to always generate
+ its own timestamps, overriding the timestamps
+ generated by clients when they called syslog().
+
config FEATURE_ROTATE_LOGFILE
bool "Rotate message files"
default y
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index fc380d9..021c1ce 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -164,9 +164,9 @@ struct globals {
/* ...then copy to parsebuf, escaping control chars */
/* (can grow x2 max) */
char parsebuf[MAX_READ*2];
- /* ...then sprintf into printbuf, adding timestamp (15 chars),
+ /* ...then sprintf into printbuf, adding timestamp (15 or 20 chars),
* host (64), fac.prio (20) to the message */
- /* (growth by: 15 + 64 + 20 + delims = ~110) */
+ /* (growth by: 20 + 64 + 20 + delims = ~115) */
char printbuf[MAX_READ*2 + 128];
};
@@ -645,17 +645,27 @@ static void timestamp_and_log(int pri, char *msg, int len)
/* Jan 18 00:11:22 msg... */
/* 01234567890123456 */
- if (len < 16 || msg[3] != ' ' || msg[6] != ' '
- || msg[9] != ':' || msg[12] != ':' || msg[15] != ' '
+ if (len >= 16 && msg[3] == ' ' && msg[6] == ' '
+ && msg[9] == ':' && msg[12] == ':' && msg[15] == ' '
) {
- time(&now);
- timestamp = ctime(&now) + 4; /* skip day of week */
- } else {
now = 0;
timestamp = msg;
msg += 16;
}
+#if !CONFIG_FEATURE_SYSLOG_TIMESTAMP_YEAR
+ else {
+#endif
+ time(&now);
+ timestamp = ctime(&now) + 4; /* skip day of week */
+#if !CONFIG_FEATURE_SYSLOG_TIMESTAMP_YEAR
+ }
+#endif
+
+#if CONFIG_FEATURE_SYSLOG_TIMESTAMP_YEAR
+ timestamp[20] = '\0';
+#else
timestamp[15] = '\0';
+#endif
if (option_mask32 & OPT_small)
sprintf(G.printbuf, "%s %s\n", timestamp, msg);
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic