On Mon, Mar 13, 2017 at 11:14:36PM +0100, Alexander Bluhm wrote:
> I think the combination of local time and time zone without fractions
> of seconds is the best choice for newsyslog. Or should we use
> 2017-03-13T21:30:04.822Z in newsyslogd?
Regarding all the Feedback I summarize:
- we need newsyslog not only for rotating syslogd log files
- there are logfiles without content for a while, so always having
timestamp at the beginning is useful
- I do not plan to move the rotating functionality into syslogd now
- I stick to RFC 5424 and will not implement another short ISO format
But I came to the conclusion to have a new different format is bad,
so I propose this diff now.
With syslogd -Z you get:
2017-03-15T23:14:09.969Z t430s newsyslog[35784]: logfile turned over
2017-03-15T23:14:50.734Z t430s bluhm: foo
And with this default traditional sylogd format
2017-03-15T23:15:16.743Z t430s newsyslog[32804]: logfile turned over
Mar 16 00:16:20 t430s bluhm: bar
ok?
bluhm
Index: usr.bin/newsyslog/newsyslog.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/usr.bin/newsyslog/newsyslog.c,v
retrieving revision 1.101
diff -u -p -r1.101 newsyslog.c
--- usr.bin/newsyslog/newsyslog.c 1 Jun 2016 16:57:48 -0000 1.101
+++ usr.bin/newsyslog/newsyslog.c 15 Mar 2017 23:13:28 -0000
@@ -142,7 +142,7 @@ int force = 0; /* Force the logs to be
char *conf = CONF; /* Configuration file to use */
time_t timenow;
char hostname[HOST_NAME_MAX+1]; /* Hostname */
-char *daytime; /* timenow in human readable form */
+char daytime[33]; /* timenow in human readable form */
char *arcdir; /* Dir to put archives in (if it exists) */
FILE *openmail(void);
@@ -402,12 +402,18 @@ send_signal(char *pidfile, int signal)
void
parse_args(int argc, char **argv)
{
+ struct timeval now;
+ struct tm *tm;
+ size_t l;
char *p;
int ch;
- timenow = time(NULL);
- daytime = ctime(&timenow) + 4;
- daytime[15] = '\0';
+ gettimeofday(&now, NULL);
+ timenow = now.tv_sec;
+ tm = gmtime(&now.tv_sec);
+ l = strftime(daytime, sizeof(daytime), "%FT%T", tm);
+ snprintf(daytime + l, sizeof(daytime) - l, ".%03ldZ",
+ now.tv_usec / 1000);
/* Let's get our hostname */
(void)gethostname(hostname, sizeof(hostname));