logging: add new date format: YYYY-MM-DD HH:MM:SS

Adds a new logging format character, %z that uses a more standard time
format of "YYYY-MM-DD HH:MM:SS".

Ticket #5764
pull/8360/head
Jason Ish 2 years ago committed by Victor Julien
parent 9f21e2bcde
commit bac8b8d26d

@ -383,8 +383,9 @@ static SCError SCLogMessageGetBuffer(struct timeval *tval, int color, SCLogOPTyp
strlcat(local_format, "%M", sizeof(local_format));
char *temp_fmt = local_format;
char *substr = temp_fmt;
struct tm local_tm;
while ( (temp_fmt = strchr(temp_fmt, SC_LOG_FMT_PREFIX)) ) {
while ((temp_fmt = strchr(temp_fmt, SC_LOG_FMT_PREFIX))) {
if ((temp - buffer) > SC_LOG_MAX_LOG_MSG_LEN) {
return 0;
}
@ -392,7 +393,23 @@ static SCError SCLogMessageGetBuffer(struct timeval *tval, int color, SCLogOPTyp
case SC_LOG_FMT_TIME:
temp_fmt[0] = '\0';
struct tm local_tm;
tms = SCLocalTime(tval->tv_sec, &local_tm);
cw = snprintf(temp, SC_LOG_MAX_LOG_MSG_LEN - (temp - buffer),
"%s%s%04d-%02d-%02d %02d:%02d:%02d%s", substr, green, tms->tm_year + 1900,
tms->tm_mon + 1, tms->tm_mday, tms->tm_hour, tms->tm_min, tms->tm_sec,
reset);
if (cw < 0)
return -1;
temp += cw;
temp_fmt++;
substr = temp_fmt;
substr++;
break;
case SC_LOG_FMT_TIME_LEGACY:
temp_fmt[0] = '\0';
tms = SCLocalTime(tval->tv_sec, &local_tm);
cw = snprintf(temp, SC_LOG_MAX_LOG_MSG_LEN - (temp - buffer),
@ -588,7 +605,7 @@ static SCError SCLogMessageGetBuffer(struct timeval *tval, int color, SCLogOPTyp
}
}
temp_fmt++;
}
}
if ((temp - buffer) > SC_LOG_MAX_LOG_MSG_LEN) {
return 0;
}

@ -188,7 +188,8 @@ typedef struct SCLogConfig_ {
} SCLogConfig;
/* The different log format specifiers supported by the API */
#define SC_LOG_FMT_TIME 't' /* Timestamp in standard format */
#define SC_LOG_FMT_TIME 'z' /* Timestamp in RFC3339 like format */
#define SC_LOG_FMT_TIME_LEGACY 't' /* Timestamp in legacy format */
#define SC_LOG_FMT_PID 'p' /* PID */
#define SC_LOG_FMT_TID 'i' /* Thread ID */
#define SC_LOG_FMT_TM 'm' /* Thread module name */

Loading…
Cancel
Save