]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
suricata: add -v[v] option to increase verbosity 576/head
authorEric Leblond <eric@regit.org>
Thu, 3 Oct 2013 12:55:35 +0000 (14:55 +0200)
committerEric Leblond <eric@regit.org>
Thu, 3 Oct 2013 12:55:35 +0000 (14:55 +0200)
This patch adds a -v option to suricata. It increases the log level
defined in the YAML.

src/suricata.c
src/suricata.h
src/util-debug.c
src/util-debug.h

index c3ae657106d0b80bacb81b6594101b29e3227e05..1e75dee94a27c1b0215478f9530a9e582eed0e9d 100644 (file)
@@ -492,6 +492,7 @@ void usage(const char *progname)
        printf("\t--service-change-params              : change service startup parameters\n");
 #endif /* OS_WIN32 */
     printf("\t-V                                   : display Suricata version\n");
+    printf("\t-v[v]                                : increase default Suricata verbosity\n");
 #ifdef UNITTESTS
     printf("\t-u                                   : run the unittests and exit\n");
     printf("\t-U, --unittest-filter=REGEX          : filter unittests with a regex\n");
@@ -904,6 +905,7 @@ static void SCInstanceInit(SCInstance *suri)
     suri->delayed_detect = 0;
     suri->daemon = 0;
     suri->offline = 0;
+    suri->verbose = 0;
 }
 
 static TmEcode PrintVersion()
@@ -1011,7 +1013,7 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri)
     /* getopt_long stores the option index here. */
     int option_index = 0;
 
-    char short_opts[] = "c:TDhi:l:q:d:r:us:S:U:VF:";
+    char short_opts[] = "c:TDhi:l:q:d:r:us:S:U:VF:v";
 
     while ((opt = getopt_long(argc, argv, short_opts, long_opts, &option_index)) != -1) {
         switch (opt) {
@@ -1471,6 +1473,9 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri)
 
             SetBpfStringFromFile(optarg);
             break;
+        case 'v':
+            suri->verbose++;
+            break;
         default:
             usage(argv[0]);
             return TM_ECODE_FAILED;
@@ -1894,7 +1899,7 @@ int main(int argc, char **argv)
 
     /* Since our config is now loaded we can finish configurating the
      * logging module. */
-    SCLogLoadConfig(suri.daemon);
+    SCLogLoadConfig(suri.daemon, suri.verbose);
 
     SCPrintVersion();
 
index d6b02411ed7c843509d8bcbac17db7d78dc246ae..551013c7eb94e022db5c2acc204ae1b00b30c60c 100644 (file)
@@ -154,6 +154,7 @@ typedef struct SCInstance_ {
     int rule_reload;
     int daemon;
     int offline;
+    int verbose;
 
     struct timeval start_time;
 
index 82d7b34e4f3849891f44fc556badfae0294d56d4..ef05fafafd8e65b0bf0ac99fff6192969d082ea6 100644 (file)
@@ -1098,7 +1098,7 @@ void SCLogInitLogModule(SCLogInitData *sc_lid)
     return;
 }
 
-void SCLogLoadConfig(int daemon)
+void SCLogLoadConfig(int daemon, int verbose)
 {
     ConfNode *outputs;
     SCLogInitData *sc_lid;
@@ -1132,6 +1132,13 @@ void SCLogLoadConfig(int daemon)
             "No default log level set, will use info.");
         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;
+    }
+
     if (ConfGet("logging.default-log-format", &sc_lid->global_log_format) != 1)
         sc_lid->global_log_format = SC_LOG_DEF_LOG_FORMAT;
 
index a778b98fd6d698568e008133094689eb3a4de17e..e5b4d705502558300d9fa75bec1bedb8bdc763e3 100644 (file)
@@ -546,6 +546,6 @@ int SCLogDebugEnabled(void);
 
 void SCLogRegisterTests(void);
 
-void SCLogLoadConfig(int daemon);
+void SCLogLoadConfig(int daemon, int verbose);
 
 #endif /* __UTIL_DEBUG_H__ */