]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
logging: fix default log format for release mode
authorVictor Julien <victor@inliniac.net>
Tue, 28 Apr 2020 07:25:43 +0000 (09:25 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 28 Apr 2020 07:25:43 +0000 (09:25 +0200)
src/util-debug.c
src/util-debug.h

index 6e3bf2c9bbafda7aa1eabc87913c4224b2e1c646..c4575cac66e9efc27c98bbd12fbf90e21ea5c91f 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2007-2010 Open Information Security Foundation
+/* Copyright (C) 2007-2020 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -971,6 +971,15 @@ static inline void SCLogSetLogLevel(SCLogInitData *sc_lid, SCLogConfig *sc_lc)
     return;
 }
 
+static inline const char *SCLogGetDefaultLogFormat(void)
+{
+    const char *prog_ver = GetProgramVersion();
+    if (strstr(prog_ver, "RELEASE") != NULL) {
+        return SC_LOG_DEF_LOG_FORMAT_REL;
+    }
+    return SC_LOG_DEF_LOG_FORMAT_DEV;
+}
+
 /**
  * \brief Internal function used to set the logging module global_log_format
  *        during the initialization phase
@@ -992,7 +1001,7 @@ static inline void SCLogSetLogFormat(SCLogInitData *sc_lid, SCLogConfig *sc_lc)
 
     /* deal with the global log format to be used */
     if (format == NULL || strlen(format) > SC_LOG_MAX_LOG_FORMAT_LEN) {
-        format = SC_LOG_DEF_LOG_FORMAT;
+        format = SCLogGetDefaultLogFormat();
 #ifndef UNITTESTS
         if (sc_lid != NULL) {
             printf("Warning: Invalid/No global_log_format supplied by user or format "
@@ -1364,7 +1373,7 @@ void SCLogLoadConfig(int daemon, int verbose)
     }
 
     if (ConfGet("logging.default-log-format", &sc_lid->global_log_format) != 1)
-        sc_lid->global_log_format = SC_LOG_DEF_LOG_FORMAT;
+        sc_lid->global_log_format = SCLogGetDefaultLogFormat();
 
     (void)ConfGet("logging.default-output-filter", &sc_lid->op_filter);
 
@@ -1552,7 +1561,7 @@ static int SCLogTestInit01(void)
     FAIL_IF_NOT(sc_log_config->op_ifaces != NULL &&
                SC_LOG_DEF_LOG_OP_IFACE == sc_log_config->op_ifaces->iface);
     FAIL_IF_NOT(sc_log_config->log_format != NULL &&
-               strcmp(SC_LOG_DEF_LOG_FORMAT, sc_log_config->log_format) == 0);
+               strcmp(SCLogGetDefaultLogFormat(), sc_log_config->log_format) == 0);
 
     SCLogDeInitLogModule();
 
@@ -1606,7 +1615,7 @@ static int SCLogTestInit02(void)
                sc_log_config->op_ifaces->next != NULL &&
                SC_LOG_OP_IFACE_CONSOLE == sc_log_config->op_ifaces->next->iface);
     FAIL_IF_NOT(sc_log_config->log_format != NULL &&
-               strcmp(SC_LOG_DEF_LOG_FORMAT, sc_log_config->log_format) == 0);
+               strcmp(SCLogGetDefaultLogFormat(), sc_log_config->log_format) == 0);
     FAIL_IF_NOT(sc_log_config->op_ifaces != NULL &&
                sc_log_config->op_ifaces->log_format != NULL &&
                strcmp("%m - %d", sc_log_config->op_ifaces->log_format) == 0);
index a2f0c601e8a99f583d2525fdfc46d827889b034d..c9c7d6e30c23b610e3c28101982688c1c0bd6b3e 100644 (file)
@@ -79,11 +79,8 @@ typedef enum {
 } SCLogOPType;
 
 /* The default log_format, if it is not supplied by the user */
-#ifdef RELEASE
-#define SC_LOG_DEF_LOG_FORMAT "%t - <%d> - "
-#else
-#define SC_LOG_DEF_LOG_FORMAT "[%i] %t - (%f:%l) <%d> (%n) -- "
-#endif
+#define SC_LOG_DEF_LOG_FORMAT_REL "%t - <%d> - "
+#define SC_LOG_DEF_LOG_FORMAT_DEV "[%i] %t - (%f:%l) <%d> (%n) -- "
 
 /* The maximum length of the log message */
 #define SC_LOG_MAX_LOG_MSG_LEN 2048