]> git.ipfire.org Git - thirdparty/ulogd2.git/commitdiff
Add -l option to set log level from command line
authorEric Leblond <eric@regit.org>
Fri, 18 Jan 2013 18:43:06 +0000 (19:43 +0100)
committerEric Leblond <eric@regit.org>
Fri, 18 Jan 2013 18:47:09 +0000 (19:47 +0100)
This patch adds a '-l' option which can be used to setup ulogd
loglevel. Command line option has precedence on the configuration
file one.

src/ulogd.c
ulogd.conf.in

index 344d3304e8ca20df3c97c94e0fd7d56956aa985a..569357200117a6d73957edaafe866b646b093087 100644 (file)
@@ -1112,6 +1112,7 @@ static void print_usage(void)
        printf("\t-V --version\tPrint version information\n");
        printf("\t-d --daemon\tDaemonize (fork into background)\n");
        printf("\t-v --verbose\tOutput info on standard output\n");
+       printf("\t-l --loglevel\tSet log level\n");
        printf("\t-c --configfile\tUse alternative Configfile\n");
        printf("\t-u --uid\tChange UID/GID\n");
        printf("\t-i --info\tDisplay infos about plugin\n");
@@ -1125,6 +1126,7 @@ static struct option opts[] = {
        { "uid", 1, NULL, 'u' },
        { "info", 1, NULL, 'i' },
        { "verbose", 0, NULL, 'v' },
+       { "loglevel", 1, NULL, 'l' },
        {NULL, 0, NULL, 0}
 };
 
@@ -1137,10 +1139,11 @@ int main(int argc, char* argv[])
        struct passwd *pw;
        uid_t uid = 0;
        gid_t gid = 0;
+       int loglevel = 0;
 
        ulogd_logfile = strdup(ULOGD_LOGFILE_DEFAULT);
 
-       while ((argch = getopt_long(argc, argv, "c:dvh::Vu:i:", opts, NULL)) != -1) {
+       while ((argch = getopt_long(argc, argv, "c:dvl:h::Vu:i:", opts, NULL)) != -1) {
                switch (argch) {
                default:
                case '?':
@@ -1189,9 +1192,17 @@ int main(int argc, char* argv[])
                case 'v':
                        verbose = 1;
                        break;
+               case 'l':
+                       loglevel = atoi(optarg);
+                       break;
                }
        }
 
+       /* command line has precedence on config file */
+       if (loglevel)
+               loglevel_ce.u.value = loglevel;
+               loglevel_ce.flag |= CONFIG_FLAG_VAL_PROTECTED;
+
        if (daemonize && verbose) {
                verbose = 0;
                ulogd_log(ULOGD_ERROR,
@@ -1204,7 +1215,7 @@ int main(int argc, char* argv[])
                          ulogd_configfile);
                warn_and_exit(daemonize);
        }
-       
+
        /* parse config file */
        if (parse_conffile("global", &ulogd_kset)) {
                ulogd_log(ULOGD_FATAL, "parse_conffile\n");
index 783cb2b5f293558639dabe9573d19bf01aece515..d5db77b4171b14ac3ff9bcc75d06214706a7e684 100644 (file)
@@ -11,8 +11,8 @@
 # logfile for status messages
 logfile="/var/log/ulogd.log"
 
-# loglevel: debug(1), info(3), notice(5), error(7) or fatal(8)
-loglevel=1
+# loglevel: debug(1), info(3), notice(5), error(7) or fatal(8) (default 5)
+loglevel=1
 
 ######################################################################
 # PLUGIN OPTIONS