From owner-freebsd-bugs Thu Sep 19 16: 0:29 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 58A4237B401 for ; Thu, 19 Sep 2002 16:00:24 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 109F243E65 for ; Thu, 19 Sep 2002 16:00:23 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.6/8.12.6) with ESMTP id g8JN0MCo096129 for ; Thu, 19 Sep 2002 16:00:22 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.6/8.12.6/Submit) id g8JN0MQi096128; Thu, 19 Sep 2002 16:00:22 -0700 (PDT) Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BF6E137B404 for ; Thu, 19 Sep 2002 15:51:57 -0700 (PDT) Received: from xor.sqrt.ca (h24-82-193-97.wp.shawcable.net [24.82.193.97]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9ED6E43E6A for ; Thu, 19 Sep 2002 15:51:51 -0700 (PDT) (envelope-from modulus@xor.sqrt.ca) Received: from xor.sqrt.ca (smmsp@localhost [127.0.0.1]) by xor.sqrt.ca (8.12.5/8.12.5) with ESMTP id g8JMponV062983 for ; Thu, 19 Sep 2002 17:51:50 -0500 (CDT) (envelope-from modulus@xor.sqrt.ca) Received: (from root@localhost) by xor.sqrt.ca (8.12.5/8.12.5/Submit) id g8JMpn1D062982; Thu, 19 Sep 2002 17:51:49 -0500 (CDT) Message-Id: <200209192251.g8JMpn1D062982@xor.sqrt.ca> Date: Thu, 19 Sep 2002 17:51:49 -0500 (CDT) From: "Chris S.J. Peron" Reply-To: "Chris S.J. Peron" To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: bin/42974: [patch] ISO 8601 date format option Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 42974 >Category: bin >Synopsis: [patch] ISO 8601 date format option >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Thu Sep 19 16:00:17 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Chris S.J. Peron >Release: FreeBSD 4.6-STABLE i386 >Organization: Seccuris Inc. >Environment: System: FreeBSD xor.sqrt.ca 4.6-STABLE FreeBSD 4.6-STABLE #4: Sun Sep 15 12:51:00 CDT 2002 modulus@xor.sqrt.ca:/usr/src/sys/compile/opcode i386 >Description: The current implementation of syslogd does not have the option to print the date of the logging events using the ``ISO 8601'' (YYYY-MM-DD) format. This option would be handy for anyone who writes external syslog parsers that insert the log entries into some database. >How-To-Repeat: N/A >Fix: I have written the option ``-D'' to have syslogd log using the ``ISO 8601'' date format. I have also patched the man page to reflect the changes. --- syslogd.o.c Thu Sep 19 15:44:36 2002 +++ syslogd.c Thu Sep 19 17:40:09 2002 @@ -129,6 +129,8 @@ #define MAXFUNIX 20 +#define MAXSTAMPLEN 32 + int nfunix = 1; const char *funixn[MAXFUNIX] = { _PATH_LOG }; int funix[MAXFUNIX]; @@ -174,7 +176,7 @@ } f_pipe; } f_un; char f_prevline[MAXSVLINE]; /* last message logged */ - char f_lasttime[16]; /* time of last occurrence */ + char f_lasttime[MAXSTAMPLEN]; /* time of last occurrence */ char f_prevhost[MAXHOSTNAMELEN]; /* host from which recd. */ int f_prevpri; /* pri of f_prevline */ int f_prevlen; /* length of f_prevline */ @@ -258,6 +260,7 @@ int Debug; /* debug flag */ int resolve = 1; /* resolve hostname */ +int iso8601stamp = 0; /* date/time printed in YYYY-MM-DD HH:MM:SS format ISO 9601 */ char LocalHostName[MAXHOSTNAMELEN]; /* our hostname */ const char *LocalDomain; /* our local domain name */ int *finet = NULL; /* Internet datagram socket */ @@ -333,7 +336,7 @@ socklen_t len; bindhostname = NULL; - while ((ch = getopt(argc, argv, "46Aa:b:cdf:kl:m:np:P:suv")) != -1) + while ((ch = getopt(argc, argv, "46Aa:b:cDdf:kl:m:np:P:suv")) != -1) switch (ch) { case '4': family = PF_INET; @@ -359,6 +362,9 @@ case 'd': /* debug */ Debug++; break; + case 'D': + iso8601stamp = 1; + break; case 'f': /* configuration file */ ConfFile = optarg; break; @@ -761,6 +767,7 @@ int flags; { struct filed *f; + struct tm *t; int i, fac, msglen, omask, prilev; const char *timestamp; char prog[NAME_MAX+1]; @@ -780,12 +787,19 @@ flags |= ADDDATE; (void)time(&now); - if (flags & ADDDATE) - timestamp = ctime(&now) + 4; - else { - timestamp = msg; - msg += 16; - msglen -= 16; + if (iso8601stamp) { + timestamp = alloca(MAXSTAMPLEN); + memset((char *)timestamp, 0, MAXSTAMPLEN); + t = localtime(&now); + strftime((char *)timestamp, MAXSTAMPLEN, "%Y-%m-%d %H:%M:%S", t); + } else { + if (flags & ADDDATE) + timestamp = ctime(&now) + 4; + else { + timestamp = msg; + msg += 16; + msglen -= 16; + } } /* skip leading blanks */ @@ -868,7 +882,7 @@ (flags & MARK) == 0 && msglen == f->f_prevlen && !strcmp(msg, f->f_prevline) && !strcasecmp(from, f->f_prevhost)) { - (void)strlcpy(f->f_lasttime, timestamp, 16); + (void)strlcpy(f->f_lasttime, timestamp, iso8601stamp ? MAXSTAMPLEN : 16); f->f_prevcount++; dprintf("msg repeated %d times, %ld sec of %d\n", f->f_prevcount, (long)(now - f->f_time), @@ -889,7 +903,7 @@ fprintlog(f, 0, (char *)NULL); f->f_repeatcount = 0; f->f_prevpri = pri; - (void)strlcpy(f->f_lasttime, timestamp, 16); + (void)strlcpy(f->f_lasttime, timestamp, iso8601stamp ? MAXSTAMPLEN : 16); (void)strlcpy(f->f_prevhost, from, sizeof(f->f_prevhost)); if (msglen < MAXSVLINE) { @@ -932,7 +946,7 @@ v++; } else { v->iov_base = f->f_lasttime; - v->iov_len = 15; + v->iov_len = iso8601stamp ? MAXSTAMPLEN : 15; v++; v->iov_base = " "; v->iov_len = 1; --- syslogd.o.8 Thu Sep 19 16:30:06 2002 +++ syslogd.8 Thu Sep 19 16:33:50 2002 @@ -40,7 +40,7 @@ .Nd log systems messages .Sh SYNOPSIS .Nm -.Op Fl 46Adknsuv +.Op Fl 46AdDknsuv .Op Fl a Ar allowed_peer .Op Fl b Ar bind_address .Op Fl f Ar config_file @@ -162,6 +162,13 @@ .Dq last message repeated N times when the output is a pipe to another program. If specified twice, disable this compression in all cases. +.It Fl D +Instruct +.Nm +to use ``ISO 8601'' style date/time formatting when writing log +records. Dates will show up in ``YYYY-MM-DD'' format. This could take +the load off of most external syslog parsers that would want to insert +records into a database. .It Fl d Put .Nm >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message