summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego 'Flameeyes' Pettenò <flameeyes@gmail.com>2008-10-01 21:15:46 +0200
committerDiego 'Flameeyes' Pettenò <flameeyes@gmail.com>2008-10-01 22:03:43 +0200
commit9fd1249bbef0712047140c81a57c34b4043a8136 (patch)
tree87991ddae9575225c48d55f6dbb3523ea8aa5430
parent354715db707564693698ebac1ef63aa6c4e13e77 (diff)
Add support for setting verbosity level for stdout/stderr output.
-rw-r--r--libdaemon/dlog.c18
-rw-r--r--libdaemon/dlog.h14
2 files changed, 32 insertions, 0 deletions
diff --git a/libdaemon/dlog.c b/libdaemon/dlog.c
index f9f6639..b9f224e 100644
--- a/libdaemon/dlog.c
+++ b/libdaemon/dlog.c
@@ -32,6 +32,20 @@
enum daemon_log_flags daemon_log_use = DAEMON_LOG_AUTO|DAEMON_LOG_STDERR;
const char* daemon_log_ident = NULL;
+static int daemon_verbosity_level = LOG_WARNING;
+
+void daemon_set_verbosity(int verbosity_prio) {
+
+ /* Allow using negative verbosity levels to hide _all_ messages */
+ if ( verbosity_prio > 0 &&
+ (verbosity_prio & LOG_PRIMASK) != LOG_PRIMASK ) {
+ daemon_log(LOG_ERR, "The value %d is not a valid priority value",
+ verbosity_prio);
+ }
+
+ daemon_verbosity_level = verbosity_prio & LOG_PRIMASK;
+}
+
void daemon_logv(int prio, const char* template, va_list arglist) {
int saved_errno;
@@ -42,6 +56,9 @@ void daemon_logv(int prio, const char* template, va_list arglist) {
vsyslog(prio | LOG_DAEMON, template, arglist);
}
+ if ( prio > daemon_verbosity_level )
+ goto end_daemon_logv;
+
if (daemon_log_use & DAEMON_LOG_STDERR) {
vfprintf(stderr, template, arglist);
fprintf(stderr, "\n");
@@ -52,6 +69,7 @@ void daemon_logv(int prio, const char* template, va_list arglist) {
fprintf(stdout, "\n");
}
+ end_daemon_logv:
errno = saved_errno;
}
diff --git a/libdaemon/dlog.h b/libdaemon/dlog.h
index 814171f..9755df6 100644
--- a/libdaemon/dlog.h
+++ b/libdaemon/dlog.h
@@ -81,6 +81,20 @@ void daemon_logv(int prio, const char* t, va_list ap);
*/
char *daemon_ident_from_argv0(char *argv0);
+/**
+ * @brief Setter for the verbosity level of standard output.
+ *
+ * @param verbose_level Minimum priority level for messages to output
+ * on standard output/error
+ *
+ * Allows to decide which messages to output on standard output/error
+ * streams. All messages are logged to syslog and this setting does
+ * not influence that.
+ *
+ * The default value is LOG_WARNING.
+ */
+void daemon_set_verbosity(int verbosity_prio);
+
#ifdef __cplusplus
}
#endif