[PATCH] syslogd: let log-message timestamps include the year

Bryan Evenson bevenson at melinkcorp.com
Wed Jul 2 15:41:14 UTC 2014


Denys,

> -----Original Message-----
> From: busybox-bounces at busybox.net [mailto:busybox-
> bounces at busybox.net] On Behalf Of Denys Vlasenko
> Sent: Wednesday, July 02, 2014 9:34 AM
> To: Joshua Judson Rosen
> Cc: busybox
> Subject: Re: [PATCH] syslogd: let log-message timestamps include the year
> 
> On Tue, May 20, 2014 at 7:06 AM, Joshua Judson Rosen
> <jrosen at harvestai.com> wrote:
> > Configurable at build time.
> >
> > Signed-off-by: Joshua Judson Rosen <jrosen at harvestai.com>
> > ---
> >  sysklogd/Config.src |   11 +++++++++++
> >  sysklogd/syslogd.c  |   24 +++++++++++++++++-------
> >  2 files changed, 28 insertions(+), 7 deletions(-)
> >
> > diff --git a/sysklogd/Config.src b/sysklogd/Config.src index
> > fcf9930..4ca0c02 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
> > f758510..d79f2fe 100644
> > --- a/sysklogd/syslogd.c
> > +++ b/sysklogd/syslogd.c
> > @@ -174,9 +174,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];  };
> >
> > @@ -701,17 +701,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_kmsg) {
> >                 log_to_kmsg(pri, msg);
> 
> The "right" solution would be to petition your libc maintainers to deprecate
> "Month DD hh:mm:ss" silliness and start using sensible (and not i18n-
> butchered) timestamps in syslog()-generated messages.
> (My personal opinion is that yyyy-mm-dd hh:mm:ss is much more practical,
> and costs only four more chars per line).
> 
> I don't know how practical is to expect libc people to hear you...
> 
> For now, maybe just a silly solution of prepending year to every line (enable-
> able by an option)?

As a Busybox syslogd user, I am all for any solution in which the year can be added to the log entry's timestamp.  Do other syslogd implementations have an option for the timestamp format, either through build configuration or a configuration file?  If not, then does Busybox need a configuration option?

Regards,
Bryan

> 
> I'm not happy with the idea of repalcing users' timestamp.
> It _does_ carry information.
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox


More information about the busybox mailing list