diff --git a/lib/isc/log.c b/lib/isc/log.c index 025dcd85d2..878d4fb654 100644 --- a/lib/isc/log.c +++ b/lib/isc/log.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: log.c,v 1.70 2001/08/08 22:54:51 gson Exp $ */ +/* $Id: log.c,v 1.71 2001/08/31 21:51:24 gson Exp $ */ /* Principal Authors: DCL */ @@ -1346,7 +1346,6 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, isc_logconfig_t *lcfg; isc_logchannel_t *channel; isc_logchannellist_t *category_channels; - isc_time_t isctime; isc_result_t result; REQUIRE(lctx == NULL || VALID_CONTEXT(lctx)); @@ -1438,37 +1437,13 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, if ((channel->flags & ISC_LOG_PRINTTIME) != 0 && time_string[0] == '\0') { - time_t now; + isc_time_t isctime; - result = isc_time_now(&isctime); + result = isc_time_now(&isctime); if (result == ISC_R_SUCCESS) - result = isc_time_secondsastimet(&isctime, - &now); - - if (result == ISC_R_SUCCESS) { - unsigned int len; - struct tm *timeptr; - - timeptr = localtime(&now); - /* - * Emulate syslog's time format, - * with milliseconds. - * - * It would be nice if the format - * were configurable. - */ - strftime(time_string, sizeof(time_string), - "%b %d %X", timeptr); - - len = strlen(time_string); - - snprintf(time_string + len, - sizeof(time_string) - len, - ".%03u ", - isc_time_nanoseconds(&isctime) - / 1000000); - - } else + isc_time_formattimestamp(&isctime, time_string, + sizeof(time_string)); + else /* * "Should never happen." */ @@ -1476,7 +1451,7 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, isc_msgcat_get(isc_msgcat, ISC_MSGSET_LOG, ISC_MSG_BADTIME, - "Bad 00 99:99:99.999 ")); + "Bad 00 99:99:99.999")); } @@ -1662,8 +1637,9 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, /* FALLTHROUGH */ case ISC_LOG_TOFILEDESC: - fprintf(FILE_STREAM(channel), "%s%s%s%s%s%s%s%s%s\n", + fprintf(FILE_STREAM(channel), "%s%s%s%s%s%s%s%s%s%s\n", printtime ? time_string : "", + printtime ? " " : "", printtag ? lcfg->tag : "", printtag ? ": " : "", printcategory ? category->name : "", diff --git a/lib/isc/unix/include/isc/time.h b/lib/isc/unix/include/isc/time.h index 8494ea9357..b670e25d55 100644 --- a/lib/isc/unix/include/isc/time.h +++ b/lib/isc/unix/include/isc/time.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: time.h,v 1.25 2001/01/09 21:58:46 bwelling Exp $ */ +/* $Id: time.h,v 1.26 2001/08/31 21:51:27 gson Exp $ */ #ifndef ISC_TIME_H #define ISC_TIME_H 1 @@ -279,6 +279,20 @@ isc_time_nanoseconds(isc_time_t *t); * The returned value is less than 1*10^9. */ +void +isc_time_formattimestamp(const isc_time_t *t, char *buf, unsigned int len); +/* + * Format the time 't' into the buffer 'buf' of length 'len', + * using a format like "Aug 30 04:06:47.997" and the local time zone. + * If the text does not fit in the buffer, the result is indeterminate, + * but is always guaranteed to be null terminated. + * + * Requires: + * 'len' > 0 + * 'buf' points to an array of at least len chars + * + */ + ISC_LANG_ENDDECLS #endif /* ISC_TIME_H */ diff --git a/lib/isc/unix/time.c b/lib/isc/unix/time.c index b7fc32ce56..04dd281286 100644 --- a/lib/isc/unix/time.c +++ b/lib/isc/unix/time.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: time.c,v 1.36 2001/08/31 05:57:57 marka Exp $ */ +/* $Id: time.c,v 1.37 2001/08/31 21:51:25 gson Exp $ */ #include @@ -389,3 +389,15 @@ isc_time_nanoseconds(isc_time_t *t) { return ((isc_uint32_t)t->nanoseconds); } + +void +isc_time_formattimestamp(const isc_time_t *t, char *buf, unsigned int len) { + time_t now; + unsigned int flen; + + now = (time_t) t->seconds; + strftime(buf, len, "%b %d %X", localtime(&now)); + flen = strlen(buf); + snprintf(buf + flen, len - flen, + ".%03u", t->nanoseconds / 1000000); +}