charon-cmd: Add --debug argument to set the default log level
authorTobias Brunner <tobias@strongswan.org>
Fri, 21 Jun 2013 13:55:52 +0000 (15:55 +0200)
committerTobias Brunner <tobias@strongswan.org>
Fri, 21 Jun 2013 13:55:52 +0000 (15:55 +0200)
src/charon-cmd/charon-cmd.c
src/charon-cmd/cmd/cmd_options.c
src/charon-cmd/cmd/cmd_options.h

index 2d8cdce..d35847d 100644 (file)
 #include "cmd/cmd_creds.h"
 
 /**
+ * Default loglevel
+ */
+static level_t default_loglevel = LEVEL_CTRL;
+
+/**
  * Loglevel configuration
  */
 static level_t levels[DBG_MAX];
@@ -63,7 +68,7 @@ static void dbg_stderr(debug_t group, level_t level, char *fmt, ...)
 {
        va_list args;
 
-       if (level <= 1)
+       if (level <= default_loglevel)
        {
                va_start(args, fmt);
                fprintf(stderr, "00[%N] ", debug_names, group);
@@ -280,6 +285,9 @@ static void handle_arguments(int argc, char *argv[], bool simple)
                        case CMD_OPT_VERSION:
                                printf("%s, strongSwan %s\n", "charon-cmd", VERSION);
                                exit(0);
+                       case CMD_OPT_DEBUG:
+                               default_loglevel = atoi(optarg);
+                               continue;
                        default:
                                if (simple)
                                {
@@ -338,7 +346,7 @@ int main(int argc, char *argv[])
        }
        for (group = 0; group < DBG_MAX; group++)
        {
-               levels[group] = LEVEL_CTRL;
+               levels[group] = default_loglevel;
        }
        charon->load_loggers(charon, levels, TRUE);
 
index 16b6b65..77d549d 100644 (file)
@@ -28,6 +28,8 @@ cmd_option_t cmd_options[CMD_OPT_COUNT] = {
          "print this usage information and exit", {}},
        { CMD_OPT_VERSION, "version", no_argument, "",
          "show version information and exit", {}},
+       { CMD_OPT_DEBUG, "debug", required_argument, "level",
+         "set the default log level (-1..4, default: 1)", {}},
        { CMD_OPT_HOST, "host", required_argument, "hostname",
          "DNS name or address to connect to", {}},
        { CMD_OPT_IDENTITY, "identity", required_argument, "identity",
index f0cf32a..4e5ba67 100644 (file)
@@ -33,6 +33,7 @@ typedef enum cmd_option_type_t cmd_option_type_t;
 enum cmd_option_type_t {
        CMD_OPT_HELP,
        CMD_OPT_VERSION,
+       CMD_OPT_DEBUG,
        CMD_OPT_HOST,
        CMD_OPT_IDENTITY,
        CMD_OPT_REMOTE_IDENTITY,