summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>2018-01-16 16:06:24 +0100
committerHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>2018-01-16 17:12:18 +0100
commit753b36c5b318d156d9ee56808ea1a6393a5286c5 (patch)
tree2d4ed9bc27e6e160584cd1caa4cb33b1b37ddf27
parentfc6fb551537b5af8988576071ff6e1240cff269f (diff)
Fix %D string expansion to not use millisec
log_selector +millisec should not change the expansion of %D (used in log_file_path and maybe other places) (cherry picked from commit d2fe8622a815e36bf66b04eb772d5ec0ba8e13af)
-rw-r--r--src/src/tod.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/src/tod.c b/src/src/tod.c
index 55933dc84..290dc6dd8 100644
--- a/src/src/tod.c
+++ b/src/src/tod.c
@@ -54,7 +54,6 @@ tod_stamp(int type)
{
struct timeval now;
struct tm * t;
-int off = 0;
gettimeofday(&now, NULL);
@@ -90,9 +89,17 @@ t = timestamps_utc ? gmtime(&now.tv_sec) : localtime(&now.tv_sec);
switch(type)
{
case tod_log_bare: /* Format used in logging without timezone */
- off = sprintf(CS timebuf, "%04d-%02d-%02d %02d:%02d:%02d",
+#ifndef COMPILE_UTILITY
+ if (LOGGING(millisec))
+ sprintf(CS timebuf, "%04d-%02d-%02d %02d:%02d:%02d.%03d",
+ 1900 + t->tm_year, 1 + t->tm_mon, t->tm_mday,
+ t->tm_hour, t->tm_min, t->tm_sec, (int)(now.tv_usec/1000));
+ else
+#endif
+ sprintf(CS timebuf, "%04d-%02d-%02d %02d:%02d:%02d",
1900 + t->tm_year, 1 + t->tm_mon, t->tm_mday,
t->tm_hour, t->tm_min, t->tm_sec);
+
break;
/* Format used as suffix of log file name when 'log_datestamp' is active. For
@@ -101,19 +108,19 @@ switch(type)
#ifdef TESTING_LOG_DATESTAMP
case tod_log_datestamp_daily:
case tod_log_datestamp_monthly:
- off = sprintf(CS timebuf, "%04d%02d%02d%02d%02d",
+ sprintf(CS timebuf, "%04d%02d%02d%02d%02d",
1900 + t->tm_year, 1 + t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min);
break;
#else
case tod_log_datestamp_daily:
- off = sprintf(CS timebuf, "%04d%02d%02d",
+ sprintf(CS timebuf, "%04d%02d%02d",
1900 + t->tm_year, 1 + t->tm_mon, t->tm_mday);
break;
case tod_log_datestamp_monthly:
#ifndef COMPILE_UTILITY
- off = sprintf(CS timebuf, "%04d%02d",
+ sprintf(CS timebuf, "%04d%02d",
1900 + t->tm_year, 1 + t->tm_mon);
#endif
break;
@@ -212,13 +219,6 @@ switch(type)
break;
}
-#ifndef COMPILE_UTILITY
-if (LOGGING(millisec) && off > 0)
- (void) sprintf(CS timebuf + off, ".%03d", (int)(now.tv_usec/1000));
-#else
-off = off; /* Compiler quietening */
-#endif
-
return timebuf;
}