]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
src/rrd_daemon.c: adds option '-V LOGLEVEL'
authorMarek Schimara <Marek.Schimara@bull.net>
Fri, 24 Jun 2016 08:27:55 +0000 (10:27 +0200)
committerMarek Schimara <Marek.Schimara@bull.net>
Tue, 23 Aug 2016 11:52:12 +0000 (13:52 +0200)
        Default log level when this flag is NOT present: LOG_ERR

src/rrd_daemon.c

index c2474ccf0ac4688a6a474339897400ff220b4bc8..8cde3b451b961f141e865f2c047c93fc95081ff3 100644 (file)
 
 #define RRDD_LOG(severity, ...) \
   do { \
-    if (stay_foreground) { \
-      fprintf(stderr, __VA_ARGS__); \
-      fprintf(stderr, "\n"); } \
-    syslog ((severity), __VA_ARGS__); \
+    if (severity <= opt_log_level) { \
+      if (stay_foreground) { \
+        fprintf(stderr, __VA_ARGS__); \
+        fprintf(stderr, "\n"); } \
+      syslog ((severity), __VA_ARGS__); \
+    } \
   } while (0)
 
 #if defined(__FreeBSD__) || defined(__APPLE__)
@@ -287,6 +289,8 @@ static pthread_mutex_t rrdfilecreate_lock = PTHREAD_MUTEX_INITIALIZER;
 
 static int opt_no_overwrite = 0; /* default for the daemon */
 
+static int opt_log_level = LOG_ERR; /* don't pollute syslog */
+
 /* Journaled updates */
 #define JOURNAL_REPLAY(s) ((s) == NULL)
 #define JOURNAL_BASE "rrd.journal"
@@ -3959,6 +3963,7 @@ static int read_options (int argc, char **argv) /* {{{ */
     {NULL, 's', OPTPARSE_REQUIRED},
     {NULL, 't', OPTPARSE_REQUIRED},
     {NULL, 'U', OPTPARSE_REQUIRED},
+    {NULL, 'V', OPTPARSE_REQUIRED},
     {NULL, 'w', OPTPARSE_REQUIRED},
     {NULL, 'z', OPTPARSE_REQUIRED},
     {0}
@@ -4047,6 +4052,53 @@ static int read_options (int argc, char **argv) /* {{{ */
         return 5;
 #endif
 
+      case 'V':
+      {
+       if (!strcmp(options.optarg, "LOG_EMERG")) {
+               opt_log_level = LOG_EMERG;
+               break;
+       }
+
+       if (!strcmp(options.optarg, "LOG_ALERT")) {
+               opt_log_level = LOG_ALERT;
+               break;
+       }
+
+       if (!strcmp(options.optarg, "LOG_CRIT")) {
+               opt_log_level = LOG_CRIT;
+               break;
+       }
+
+       if (!strcmp(options.optarg, "LOG_ERR")) {
+               opt_log_level = LOG_ERR;
+               break;
+       }
+
+       if (!strcmp(options.optarg, "LOG_WARNING")) {
+               opt_log_level = LOG_WARNING;
+               break;
+       }
+
+       if (!strcmp(options.optarg, "LOG_NOTICE")) {
+               opt_log_level = LOG_NOTICE;
+               break;
+       }
+
+       if (!strcmp(options.optarg, "LOG_INFO")) {
+               opt_log_level = LOG_INFO;
+               break;
+       }
+
+       if (!strcmp(options.optarg, "LOG_DEBUG")) {
+               opt_log_level = LOG_DEBUG;
+               break;
+       }
+
+       fprintf(stderr, "Unrecognized log level '%s'; falling back to "
+               "default LOG_ERR.\n", options.optarg);
+       break;
+      }
+
       case 'L':
       case 'l':
       {
@@ -4393,6 +4445,8 @@ static int read_options (int argc, char **argv) /* {{{ */
                             "for that group)\n"
             "  -t <threads>  Number of write threads.\n"
             "  -U <user>     Unprivileged user account used when running.\n"
+            "  -V <LOGLEVEL> Max syslog level to log with, with LOG_DEBUG being\n"
+            "                the maximum and LOG_EMERG minimum; see syslog.h\n"
             "  -w <seconds>  Interval in which to write data.\n"
             "  -z <delay>    Delay writes up to <delay> seconds to spread load\n"
             "\n"