log-time-ascii option

git-svn-id: file:///svn/unbound/trunk@1465 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
Wouter Wijngaards 2009-02-06 12:51:45 +00:00
parent 0007337afe
commit 63d3cb7ff4
15 changed files with 1225 additions and 1137 deletions

View file

@ -118,6 +118,9 @@
/* Define to 1 if you have the `ldns' library (-lldns). */
#undef HAVE_LIBLDNS
/* Define to 1 if you have the `localtime_r' function. */
#undef HAVE_LOCALTIME_R
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
to 0 otherwise. */
#undef HAVE_MALLOC
@ -212,6 +215,9 @@
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the `strftime' function. */
#undef HAVE_STRFTIME
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H

4
configure vendored
View file

@ -25284,7 +25284,9 @@ fi
for ac_func in tzset sigprocmask fcntl getpwnam getrlimit setsid sbrk chroot kill sleep usleep random srandom recvmsg sendmsg writev setresuid setreuid setresgid setregid glob initgroups daemon
for ac_func in tzset sigprocmask fcntl getpwnam getrlimit setsid sbrk chroot kill sleep usleep random srandom recvmsg sendmsg writev setresuid setreuid setresgid setregid glob initgroups daemon strftime localtime_r
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
{ echo "$as_me:$LINENO: checking for $ac_func" >&5

View file

@ -854,7 +854,7 @@ AC_CHECK_GETADDRINFO_WITH_INCLUDES
if test $ac_cv_func_getaddrinfo = no; then
AC_LIBOBJ([fake-rfc2553])
fi
AC_CHECK_FUNCS([tzset sigprocmask fcntl getpwnam getrlimit setsid sbrk chroot kill sleep usleep random srandom recvmsg sendmsg writev setresuid setreuid setresgid setregid glob initgroups daemon])
AC_CHECK_FUNCS([tzset sigprocmask fcntl getpwnam getrlimit setsid sbrk chroot kill sleep usleep random srandom recvmsg sendmsg writev setresuid setreuid setresgid setregid glob initgroups daemon strftime localtime_r])
# check if setreuid en setregid fail, on MacOSX10.4(darwin8).
if echo $build_os | grep darwin8 > /dev/null; then

View file

@ -8,6 +8,8 @@
Does not allow literal newlines inside quoted strings anymore.
- verbosity level 5 logs customer IP for new requestlist entries.
- test fix, lexer and cancel test.
- new option log-time-ascii: yes if you enable it prints timestamps
in the log file as Feb 06 13:45:26 (just like syslog does).
5 February 2009: Wouter
- ldns 1.5.0 rc as tarball included.

View file

@ -192,6 +192,9 @@ server:
# log to, with identity "unbound". If yes, it overrides the logfile.
# use-syslog: yes
# print UTC timestamp in ascii to logfile, default is secs since 1970.
# log-time-ascii: no
# the pid file. Can be an absolute path outside of chroot/work dir.
# pidfile: "@UNBOUND_PIDFILE@"

View file

@ -337,6 +337,11 @@ The log facility LOG_DAEMON is used, with identity "unbound".
The logfile setting is overridden when use\-syslog is turned on.
The default is to log to syslog.
.TP
.B log\-time\-ascii: \fI<yes or no>
Sets logfile lines to use a timestamp in UTC ascii. Default is no, which
prints the seconds since 1970 in brackets. No effect if using syslog, in
that case syslog formats the timestamp printed into the log files.
.TP
.B pidfile: \fI<filename>
The process id is written to the file. Default is "@UNBOUND_PIDFILE@".
So,

View file

@ -83,6 +83,7 @@ config_create()
cfg->do_udp = 1;
cfg->do_tcp = 1;
cfg->use_syslog = 1;
cfg->log_time_ascii = 0;
#ifndef USE_WINSOCK
cfg->outgoing_num_ports = 256;
#else
@ -805,6 +806,7 @@ void
config_apply(struct config_file* config)
{
MAX_TTL = (uint32_t)config->max_ttl;
log_set_time_asc(config->log_time_ascii);
}
/**

View file

@ -171,6 +171,8 @@ struct config_file {
/** should log messages be sent to syslogd */
int use_syslog;
/** log timestamp in ascii UTC */
int log_time_ascii;
/** do not report identity (id.server, hostname.bind) */
int hide_identity;

File diff suppressed because it is too large Load diff

View file

@ -199,6 +199,7 @@ neg-cache-size{COLON} { YDVAR(1, VAR_NEG_CACHE_SIZE) }
val-nsec3-keysize-iterations{COLON} {
YDVAR(1, VAR_VAL_NSEC3_KEYSIZE_ITERATIONS) }
use-syslog{COLON} { YDVAR(1, VAR_USE_SYSLOG) }
log-time-ascii{COLON} { YDVAR(1, VAR_LOG_TIME_ASCII) }
local-zone{COLON} { YDVAR(2, VAR_LOCAL_ZONE) }
local-data{COLON} { YDVAR(1, VAR_LOCAL_DATA) }
local-data-ptr{COLON} { YDVAR(1, VAR_LOCAL_DATA_PTR) }

File diff suppressed because it is too large Load diff

View file

@ -136,7 +136,8 @@
VAR_LOCAL_DATA_PTR = 352,
VAR_JOSTLE_TIMEOUT = 353,
VAR_STUB_PRIME = 354,
VAR_UNWANTED_REPLY_THRESHOLD = 355
VAR_UNWANTED_REPLY_THRESHOLD = 355,
VAR_LOG_TIME_ASCII = 356
};
#endif
/* Tokens. */
@ -238,6 +239,7 @@
#define VAR_JOSTLE_TIMEOUT 353
#define VAR_STUB_PRIME 354
#define VAR_UNWANTED_REPLY_THRESHOLD 355
#define VAR_LOG_TIME_ASCII 356
@ -249,7 +251,7 @@ typedef union YYSTYPE
char* str;
}
/* Line 1489 of yacc.c. */
#line 253 "util/configparser.h"
#line 255 "util/configparser.h"
YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1

View file

@ -96,7 +96,7 @@ extern struct config_parser_state* cfg_parser;
%token VAR_CONTROL_INTERFACE VAR_CONTROL_PORT VAR_SERVER_KEY_FILE
%token VAR_SERVER_CERT_FILE VAR_CONTROL_KEY_FILE VAR_CONTROL_CERT_FILE
%token VAR_EXTENDED_STATISTICS VAR_LOCAL_DATA_PTR VAR_JOSTLE_TIMEOUT
%token VAR_STUB_PRIME VAR_UNWANTED_REPLY_THRESHOLD
%token VAR_STUB_PRIME VAR_UNWANTED_REPLY_THRESHOLD VAR_LOG_TIME_ASCII
%%
toplevelvars: /* empty */ | toplevelvars toplevelvar ;
@ -143,7 +143,7 @@ content_server: server_num_threads | server_verbosity | server_port |
server_harden_referral_path | server_private_address |
server_private_domain | server_extended_statistics |
server_local_data_ptr | server_jostle_timeout |
server_unwanted_reply_threshold
server_unwanted_reply_threshold | server_log_time_ascii
;
stubstart: VAR_STUB_ZONE
{
@ -374,6 +374,15 @@ server_use_syslog: VAR_USE_SYSLOG STRING
free($2);
}
;
server_log_time_ascii: VAR_LOG_TIME_ASCII STRING
{
OUTYY(("P(server_log_time_ascii:%s)\n", $2));
if(strcmp($2, "yes") != 0 && strcmp($2, "no") != 0)
yyerror("expected yes or no.");
else cfg_parser->cfg->log_time_ascii = (strcmp($2, "yes")==0);
free($2);
}
;
server_chroot: VAR_CHROOT STRING
{
OUTYY(("P(server_chroot:%s)\n", $2));

View file

@ -71,6 +71,8 @@ static int logging_to_syslog = 0;
#endif /* HAVE_SYSLOG_H */
/** time to print in log, if NULL, use time(2) */
static uint32_t* log_now = NULL;
/** print time in UTC or in secondsfrom1970 */
static int log_time_asc = 0;
void
log_init(const char* filename, int use_syslog, const char* chrootdir)
@ -139,13 +141,20 @@ void log_set_time(uint32_t* t)
log_now = t;
}
void log_set_time_asc(int use_asc)
{
log_time_asc = use_asc;
}
void
log_vmsg(int pri, const char* type,
const char *format, va_list args)
{
char message[MAXSYSLOGMSGLEN];
char tmbuf[32];
unsigned int* tid = (unsigned int*)ub_thread_key_get(logkey);
uint32_t now;
time_t now;
struct tm tm;
(void)pri;
vsnprintf(message, sizeof(message), format, args);
#ifdef HAVE_SYSLOG_H
@ -157,8 +166,16 @@ log_vmsg(int pri, const char* type,
#endif /* HAVE_SYSLOG_H */
if(!logfile) return;
if(log_now)
now = *log_now;
else now = (uint32_t)time(NULL);
now = (time_t)*log_now;
else now = (time_t)time(NULL);
#if defined(HAVE_STRFTIME) && defined(HAVE_LOCALTIME_R)
if(log_time_asc && strftime(tmbuf, sizeof(tmbuf), "%b %d %H:%M:%S",
localtime_r(&now, &tm))%(sizeof(tmbuf)) != 0) {
/* %sizeof buf!=0 because old strftime returned max on error */
fprintf(logfile, "%s %s[%d:%x] %s: %s\n", tmbuf,
ident, (int)getpid(), tid?*tid:0, type, message);
} else
#endif
fprintf(logfile, "[%u] %s[%d:%x] %s: %s\n", (unsigned)now,
ident, (int)getpid(), tid?*tid:0, type, message);
fflush(logfile);

View file

@ -114,6 +114,14 @@ void log_ident_set(const char* id);
*/
void log_set_time(uint32_t* t);
/**
* Set if the time value is printed ascii or decimal in log entries.
* @param use_asc: if true, ascii is printed, otherwise decimal.
* If the conversion fails or you have no time functions,
* decimal is printed.
*/
void log_set_time_asc(int use_asc);
/**
* Log informational message.
* Pass printf formatted arguments. No trailing newline is needed.