summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configure.ac4
-rw-r--r--libdaemon/dlog.c18
-rw-r--r--libdaemon/dlog.h14
3 files changed, 34 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index 0eb0114..a185464 100644
--- a/configure.ac
+++ b/configure.ac
@@ -21,7 +21,7 @@
AC_PREREQ(2.62)
-AC_INIT([libdaemon],[0.13],[mzqnrzba (at) 0pointer (dot) de])
+AC_INIT([libdaemon],[0.14],[mzqnrzba (at) 0pointer (dot) de])
AC_CONFIG_SRCDIR([libdaemon/dfork.c])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
@@ -30,7 +30,7 @@ AM_INIT_AUTOMAKE([foreign 1.9 -Wall])
AC_SUBST(PACKAGE_URL, [http://0pointer.de/lennart/projects/libdaemon/])
-AC_SUBST(LIBDAEMON_VERSION_INFO, [4:0:4])
+AC_SUBST(LIBDAEMON_VERSION_INFO, [5:0:5])
if type -p stow > /dev/null && test -d /usr/local/stow ; then
AC_MSG_NOTICE([*** Found /usr/local/stow: default install prefix set to /usr/local/stow/${PACKAGE_NAME}-${PACKAGE_VERSION} ***])
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