From: Nick Porter Date: Tue, 15 Jul 2025 16:03:47 +0000 (+0100) Subject: Add timestamp option to log config X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=efcae3a0fe33fdf1ac1c05fd0791fa1291880076;p=thirdparty%2Ffreeradius-server.git Add timestamp option to log config So that timestamps can be added to debug logs at level 1 and 2 if needed. --- diff --git a/raddb/radiusd.conf.in b/raddb/radiusd.conf.in index 1bf4b8efcf..3fe562843d 100644 --- a/raddb/radiusd.conf.in +++ b/raddb/radiusd.conf.in @@ -461,6 +461,14 @@ log { # by seeing what is actually being sent. # # suppress_secrets = no + + # Add timestamps to debug logs + # + # By default, at debug level 1 and 2, messages are produced + # without timestamps. + # + # Enabling this option will include timestamps on all debug logs. +# timestamp = no } # The program to execute to do concurrency checks. diff --git a/src/include/log.h b/src/include/log.h index 2736591779..f978496a0a 100644 --- a/src/include/log.h +++ b/src/include/log.h @@ -70,6 +70,7 @@ typedef struct fr_log_t { log_dst_t dst; //!< Log destination. char const *file; //!< Path to log file. char const *debug_file; //!< Path to debug log file. + bool timestamp; //!< Should logs always have timestamps. } fr_log_t; typedef void (*radlog_func_t)(log_type_t lvl, log_lvl_t priority, REQUEST *, char const *, va_list ap); diff --git a/src/main/log.c b/src/main/log.c index 1ca2f914c2..cc31fdd036 100644 --- a/src/main/log.c +++ b/src/main/log.c @@ -219,6 +219,7 @@ fr_log_t default_log = { .dst = L_DST_STDOUT, .file = NULL, .debug_file = NULL, + .timestamp = false, }; static int stderr_fd = -1; //!< The original unmolested stderr file descriptor @@ -401,7 +402,7 @@ int vradlog(log_type_t type, char const *msg, va_list ap) * of debugging. */ if (default_log.dst != L_DST_SYSLOG) { - if ((rad_debug_lvl != 1) && (rad_debug_lvl != 2)) { + if (((rad_debug_lvl != 1) && (rad_debug_lvl != 2)) || default_log.timestamp) { time_t timeval; timeval = time(NULL); diff --git a/src/main/mainconfig.c b/src/main/mainconfig.c index 147caaf323..4120392a91 100644 --- a/src/main/mainconfig.c +++ b/src/main/mainconfig.c @@ -201,6 +201,7 @@ static const CONF_PARSER log_config[] = { { "use_utc", FR_CONF_POINTER(PW_TYPE_BOOLEAN, &log_dates_utc), NULL }, { "msg_denied", FR_CONF_POINTER(PW_TYPE_STRING, &main_config.denied_msg), "You are already logged in - access denied" }, { "suppress_secrets", FR_CONF_POINTER(PW_TYPE_BOOLEAN, &main_config.suppress_secrets), NULL }, + { "timestamp", FR_CONF_POINTER(PW_TYPE_BOOLEAN, &default_log.timestamp), NULL }, CONF_PARSER_TERMINATOR };