]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
output: add %D for compact log level
authorVictor Julien <vjulien@oisf.net>
Thu, 1 Dec 2022 11:51:03 +0000 (12:51 +0100)
committerVictor Julien <vjulien@oisf.net>
Tue, 20 Dec 2022 07:51:33 +0000 (08:51 +0100)
src/util-debug.c
src/util-debug.h

index 3903669b9028f1341445d60485f697e81897a0c1..f26d833d9e6ee9390a59da2a9bef9426100ff7c8 100644 (file)
@@ -36,6 +36,7 @@
 #include "util-syslog.h"
 #include "util-time.h"
 
+// clang-format off
 /* holds the string-enum mapping for the enums held in the table SCLogLevel */
 SCEnumCharMap sc_log_level_map[ ] = {
     { "Not set",        SC_LOG_NOTSET},
@@ -53,6 +54,22 @@ SCEnumCharMap sc_log_level_map[ ] = {
     { NULL,             -1 }
 };
 
+SCEnumCharMap sc_log_slevel_map[] = {
+    { "Not set",        SC_LOG_NOTSET },
+    { "None",           SC_LOG_NONE },
+    { "E",              SC_LOG_EMERGENCY },
+    { "A",              SC_LOG_ALERT },
+    { "C",              SC_LOG_CRITICAL },
+    { "E",              SC_LOG_ERROR },
+    { "W",              SC_LOG_WARNING },
+    { "i",              SC_LOG_NOTICE },
+    { "i",              SC_LOG_INFO },
+    { "i",              SC_LOG_PERF },
+    { "i",              SC_LOG_CONFIG },
+    { "d",              SC_LOG_DEBUG },
+    { NULL,             -1 }
+};
+
 /* holds the string-enum mapping for the enums held in the table SCLogOPIface */
 SCEnumCharMap sc_log_op_iface_map[ ] = {
     { "Console",        SC_LOG_OP_IFACE_CONSOLE },
@@ -60,6 +77,7 @@ SCEnumCharMap sc_log_op_iface_map[ ] = {
     { "Syslog",         SC_LOG_OP_IFACE_SYSLOG },
     { NULL,             -1 }
 };
+// clang-format on
 
 #if defined (OS_WIN32)
 /**
@@ -443,6 +461,34 @@ static SCError SCLogMessageGetBuffer(struct timeval *tval, int color, SCLogOPTyp
                     else if (log_level == SC_LOG_NOTICE)
                         cw = snprintf(temp, SC_LOG_MAX_LOG_MSG_LEN - (temp - buffer),
                                   "%s%s%s%s", substr, yellowb, s, reset);
+                    else
+                        cw = snprintf(temp, SC_LOG_MAX_LOG_MSG_LEN - (temp - buffer), "%s%s%s%s",
+                                substr, yellow, s, reset);
+                } else {
+                    cw = snprintf(temp, SC_LOG_MAX_LOG_MSG_LEN - (temp - buffer), "%s%s", substr,
+                            "INVALID");
+                }
+                if (cw < 0)
+                    return -1;
+                temp += cw;
+                temp_fmt++;
+                substr = temp_fmt;
+                substr++;
+                break;
+
+            case SC_LOG_FMT_LOG_SLEVEL:
+                temp_fmt[0] = '\0';
+                s = SCMapEnumValueToName(log_level, sc_log_slevel_map);
+                if (s != NULL) {
+                    if (log_level <= SC_LOG_ERROR)
+                        cw = snprintf(temp, SC_LOG_MAX_LOG_MSG_LEN - (temp - buffer), "%s%s%s%s",
+                                substr, redb, s, reset);
+                    else if (log_level == SC_LOG_WARNING)
+                        cw = snprintf(temp, SC_LOG_MAX_LOG_MSG_LEN - (temp - buffer), "%s%s%s%s",
+                                substr, red, s, reset);
+                    else if (log_level == SC_LOG_NOTICE)
+                        cw = snprintf(temp, SC_LOG_MAX_LOG_MSG_LEN - (temp - buffer), "%s%s%s%s",
+                                substr, yellowb, s, reset);
                     else
                         cw = snprintf(temp, SC_LOG_MAX_LOG_MSG_LEN - (temp - buffer),
                                   "%s%s%s%s", substr, yellow, s, reset);
index 9b97c10ccf84852b0feee99064c9e48e65897603..c6219fc2b65e1b320966a73b5e6d0c628ad302c1 100644 (file)
@@ -193,6 +193,7 @@ typedef struct SCLogConfig_ {
 #define SC_LOG_FMT_TID              'i' /* Thread ID */
 #define SC_LOG_FMT_TM               'm' /* Thread module name */
 #define SC_LOG_FMT_LOG_LEVEL        'd' /* Log level */
+#define SC_LOG_FMT_LOG_SLEVEL       'D' /* Log level */
 #define SC_LOG_FMT_FILE_NAME        'f' /* File name */
 #define SC_LOG_FMT_LINE             'l' /* Line number */
 #define SC_LOG_FMT_FUNCTION         'n' /* Function */