If you have:
qb_log_filter_ctl(QB_LOG_SYSLOG, QB_LOG_FILTER_ADD,
QB_LOG_FILTER_FILE, "hack.c", LOG_DEBUG);
these logs will not make there way to /var/log/messags
without reconfiguring syslog.
So to help on the fly debugging do the following:
qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_PRIORITY_BUMP,
LOG_INFO - LOG_DEBUG);
Now all messages that have the QB_LOG_SYSLOG target set
will have their priority bumped before going to syslog().
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
include/qb/qblog.h | 7 +++++++
lib/log.c | 3 +++
lib/log_int.h | 1 +
lib/log_syslog.c | 8 +++++++-
4 files changed, 18 insertions(+), 1 deletions(-)
diff --git a/include/qb/qblog.h b/include/qb/qblog.h
index a5317b1..a5a1b69 100644
--- a/include/qb/qblog.h
+++ b/include/qb/qblog.h
@@ -82,6 +82,12 @@ extern "C" {
* qb_log_ctl(mytarget, QB_LOG_CONF_THREADED, QB_TRUE);
* @endcode
*
+ * To workaround your syslog daemon filtering all messages > LOG_INFO
+ * @code
+ * qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_PRIORITY_BUMP,
+ * LOG_INFO - LOG_DEBUG);
+ * @endcode
+ *
* @par Filtering messages.
* To have more power over what log messages go to which target you can apply
* filters to the targets. What happens is the desired callsites have the
@@ -312,6 +318,7 @@ enum qb_log_conf {
QB_LOG_CONF_DEBUG,
QB_LOG_CONF_SIZE,
QB_LOG_CONF_THREADED,
+ QB_LOG_CONF_PRIORITY_BUMP,
};
enum qb_log_filter_type {
diff --git a/lib/log.c b/lib/log.c
index a281df2..5b66bfd 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -598,6 +598,9 @@ int32_t qb_log_ctl(int32_t t, enum qb_log_conf c, int32_t arg)
need_reload = QB_TRUE;
}
break;
+ case QB_LOG_CONF_PRIORITY_BUMP:
+ conf[t].priority_bump = arg;
+ break;
case QB_LOG_CONF_SIZE:
conf[t].size = arg;
if (t == QB_LOG_BLACKBOX) {
diff --git a/lib/log_int.h b/lib/log_int.h
index 755b755..34f82e0 100644
--- a/lib/log_int.h
+++ b/lib/log_int.h
@@ -47,6 +47,7 @@ struct qb_log_target {
char name[PATH_MAX];
struct qb_list_head filter_head;
int32_t facility;
+ int32_t priority_bump;
int32_t debug;
size_t size;
char *format;
diff --git a/lib/log_syslog.c b/lib/log_syslog.c
index 5544e39..8a1ec8b 100644
--- a/lib/log_syslog.c
+++ b/lib/log_syslog.c
@@ -27,10 +27,16 @@ static void _syslog_logger(struct qb_log_target *t,
time_t timestamp, const char *msg)
{
char output_buffer[COMBINE_BUFFER_SIZE];
+ int32_t final_priority = cs->priority + t->priority_bump;
qb_log_target_format(t, cs, timestamp, msg, output_buffer);
- syslog(cs->priority, "%s", output_buffer);
+ if (final_priority > LOG_DEBUG) {
+ return;
+ } else if (final_priority < LOG_EMERG) {
+ final_priority = LOG_EMERG;
+ }
+ syslog(final_priority, "%s", output_buffer);
}
static void _syslog_close(struct qb_log_target *t)
--
1.7.4