]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
logging: used fixed levels of verbosity for -v, -vv...
authorJason Ish <jason.ish@oisf.net>
Wed, 2 Oct 2019 22:38:50 +0000 (16:38 -0600)
committerVictor Julien <victor@inliniac.net>
Thu, 10 Oct 2019 05:41:05 +0000 (07:41 +0200)
Change the meaning of the verbosity flag to change the log
level to fixed levels instead of being relative to whats
configured.

-v    => INFO
-vv   => PERF
-vvv  => CONIFG
-vvvv => DEBUG

But do now allow -v to decrease the verbosity.

Bug #1851

src/util-debug.c

index aea8be74002178b00f12598bd890f609d3661382..33185f99d9427238c21675d5f434921383aa2355 100644 (file)
@@ -1299,6 +1299,13 @@ void SCLogLoadConfig(int daemon, int verbose)
     SCLogInitData *sc_lid;
     int have_logging = 0;
     int max_level = 0;
+    SCLogLevel min_level = 0;
+
+    /* If verbose logging was requested, set the minimum as
+     * SC_LOG_NOTICE plus the extra verbosity. */
+    if (verbose) {
+        min_level = SC_LOG_NOTICE + verbose;
+    }
 
     outputs = ConfGetNode("logging.outputs");
     if (outputs == NULL) {
@@ -1315,24 +1322,17 @@ void SCLogLoadConfig(int daemon, int verbose)
     /* Get default log level and format. */
     const char *default_log_level_s = NULL;
     if (ConfGet("logging.default-log-level", &default_log_level_s) == 1) {
-        sc_lid->global_log_level =
+        SCLogLevel default_log_level =
             SCMapEnumNameToValue(default_log_level_s, sc_log_level_map);
-        if (sc_lid->global_log_level == -1) {
+        if (default_log_level == -1) {
             SCLogError(SC_ERR_INVALID_ARGUMENT, "Invalid default log level: %s",
                 default_log_level_s);
             exit(EXIT_FAILURE);
         }
+        sc_lid->global_log_level = MAX(min_level, default_log_level);
     }
     else {
-        SCLogWarning(SC_ERR_MISSING_CONFIG_PARAM,
-            "No default log level set, will use notice.");
-        sc_lid->global_log_level = SC_LOG_NOTICE;
-    }
-
-    if (verbose) {
-        sc_lid->global_log_level += verbose;
-        if (sc_lid->global_log_level > SC_LOG_LEVEL_MAX)
-            sc_lid->global_log_level = SC_LOG_LEVEL_MAX;
+        sc_lid->global_log_level = MAX(min_level, SC_LOG_NOTICE);
     }
 
     if (ConfGet("logging.default-log-format", &sc_lid->global_log_format) != 1)
@@ -1389,6 +1389,9 @@ void SCLogLoadConfig(int daemon, int verbose)
             max_level = MAX(max_level, level);
         }
 
+        /* Increase the level of extra verbosity was requested. */
+        level = MAX(min_level, level);
+
         if (strcmp(output->name, "console") == 0) {
             op_iface_ctx = SCLogInitConsoleOPIface(format, level, type);
         }