Commit c3ee335e authored by Daniel Salzman's avatar Daniel Salzman

log: set short log time format as a default

Rename the option --enable-shortlog to the option --enable-microseconds-log.

Change-Id: I864ea1f21f4c0aa0daef57143b58ae4307b3c7ca
parent ee477033
......@@ -146,10 +146,10 @@ AC_ARG_ENABLE([lto],
*) AC_MSG_ERROR([bad value ${enableval} for --enable-lto]) ;;
esac])
# Check for shortlog
AC_ARG_ENABLE([shortlog],
AS_HELP_STRING([--enable-shortlog], [enable shorter date format in log messages [default=no]]),
AC_DEFINE([ENABLE_SHORTLOG], [1], [short log format]))
# Check for enable microseconds in log messages
AC_ARG_ENABLE([microseconds-log],
AS_HELP_STRING([--enable-microseconds-log], [enable microseconds in log messages [default=no]]),
AC_DEFINE([ENABLE_MICROSECONDS_LOG], [1], [microseconds in log messages]))
AX_CHECK_COMPILER_FLAGS("-fpredictive-commoning", [CFLAGS="$CFLAGS -fpredictive-commoning"], [])
......
......@@ -210,7 +210,7 @@ static int _log_msg(logsrc_t src, int level, const char *msg)
// Convert level to mask
level = LOG_MASK(level);
/* Prefix date and time. */
char tstr[128] = {0};
int tlen = 0;
......@@ -219,10 +219,16 @@ static int _log_msg(logsrc_t src, int level, const char *msg)
gettimeofday(&tv, NULL);
time_t sec = tv.tv_sec;
if (localtime_r(&sec, &lt) != NULL) {
bool precise = false;
#ifdef ENABLE_MICROSECONDS_LOG
precise = true;
#endif /* ENABLE_MICROSECONDS_LOG */
tlen = strftime(tstr, sizeof(tstr),
"%Y-%m-%dT%H:%M:%S ", &lt);
#ifndef ENABLE_SHORTLOG
if (tlen > 0) {
if (precise && tlen > 0) {
char pm = (lt.tm_gmtoff > 0) ? '+' : '-';
snprintf(tstr + tlen - 1, sizeof(tstr) - tlen + 1,
".%.6lu%c%.2u:%.2u ",
......@@ -230,7 +236,6 @@ static int _log_msg(logsrc_t src, int level, const char *msg)
(unsigned int)lt.tm_gmtoff / 3600,
(unsigned int)(lt.tm_gmtoff / 60) % 60);
}
#endif /* ENABLE_SHORTLOG */
}
// Log streams
......@@ -280,7 +285,7 @@ int log_msg(logsrc_t src, int level, const char *msg, ...)
case LOG_FATAL: prefix = "[fatal] "; break;
default: break;
}
/* Prepend prefix. */
int plen = strlen(prefix);
if (plen > buflen) {
......@@ -348,7 +353,7 @@ int log_update_privileges(int uid, int gid)
if (fchown(fileno(LOG_FDS[i]), uid, gid) < 0) {
return KNOT_ERROR;
}
}
return KNOT_EOK;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment