mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-03 08:05:21 +00:00
added isc_time_formattimestamp() (Unix only so far);
call it from log.c [RT #1687]
This commit is contained in:
@@ -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);
|
||||
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 : "",
|
||||
|
@@ -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 */
|
||||
|
@@ -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 <config.h>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user