From: Marek Schimara Date: Fri, 24 Jun 2016 08:27:55 +0000 (+0200) Subject: src/rrd_daemon.c: adds option '-V LOGLEVEL' X-Git-Tag: v1.7.0~39^2~1 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=5ce8198e7735776d0e121b2e27287316d04608f8;p=thirdparty%2Frrdtool-1.x.git src/rrd_daemon.c: adds option '-V LOGLEVEL' Default log level when this flag is NOT present: LOG_ERR --- diff --git a/src/rrd_daemon.c b/src/rrd_daemon.c index c2474ccf..8cde3b45 100644 --- a/src/rrd_daemon.c +++ b/src/rrd_daemon.c @@ -116,10 +116,12 @@ #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 Number of write threads.\n" " -U Unprivileged user account used when running.\n" + " -V Max syslog level to log with, with LOG_DEBUG being\n" + " the maximum and LOG_EMERG minimum; see syslog.h\n" " -w Interval in which to write data.\n" " -z Delay writes up to seconds to spread load\n" "\n"