summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorGergely Nagy <algernon@madhouse-project.org>2012-03-20 07:55:22 +0100
committerGergely Nagy <algernon@madhouse-project.org>2012-03-20 07:55:22 +0100
commit6627c0249ed53580a173e7b0190937c14fc2d2cd (patch)
tree95023d3b80f7b92f2224bdfbb051dd318bcc3950 /lib
parent7ffd832758c8284bc95aecfc6d88705b80edab64 (diff)
downloadlibumberlog-6627c0249ed53580a173e7b0190937c14fc2d2cd.tar.gz
libumberlog-6627c0249ed53580a173e7b0190937c14fc2d2cd.tar.xz
libumberlog-6627c0249ed53580a173e7b0190937c14fc2d2cd.zip
Implement a wrapper for setlogmask()
Since we'd like to avoid doing useless work during logging, wrap setlogmask() too, and save the mask set, so during _cee_vsyslog(), we can bail out early, if our priority is not set in the mask. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/cee-syslog.c24
-rw-r--r--lib/cee-syslog.h1
2 files changed, 23 insertions, 2 deletions
diff --git a/lib/cee-syslog.c b/lib/cee-syslog.c
index 724372c..3c6e3ca 100644
--- a/lib/cee-syslog.c
+++ b/lib/cee-syslog.c
@@ -42,12 +42,15 @@
static void (*old_syslog) ();
static void (*old_openlog) ();
+static int (*old_setlogmask) ();
static void cee_init (void) __attribute__((constructor));
static __thread struct
{
+ int mask;
int flags;
+
int facility;
pid_t pid;
} cee_sys_settings;
@@ -57,12 +60,14 @@ cee_init (void)
{
old_syslog = dlsym (RTLD_NEXT, "syslog");
old_openlog = dlsym (RTLD_NEXT, "openlog");
+ old_setlogmask = dlsym (RTLD_NEXT, "setlogmask");
}
void
cee_openlog (const char *ident, int option, int facility)
{
old_openlog (ident, option, facility);
+ cee_sys_settings.mask = old_setlogmask (0);
cee_sys_settings.flags = option;
cee_sys_settings.facility = facility;
cee_sys_settings.pid = getpid ();
@@ -216,9 +221,13 @@ static inline void
_cee_vsyslog (int format_version, int priority,
const char *msg_format, va_list ap)
{
- struct json_object *jo = json_object_new_object ();
+ struct json_object *jo;
+
+ if (!(cee_sys_settings.mask & priority))
+ return;
- _cee_vformat (jo, format_version, priority, msg_format, ap);
+ jo = _cee_vformat (json_object_new_object (), format_version,
+ priority, msg_format, ap);
old_syslog (priority, "@cee:%s", json_object_to_json_string (jo));
json_object_put (jo);
}
@@ -245,6 +254,14 @@ _cee_old_syslog (int priority, const char *msg_format, ...)
va_end (ap);
}
+int
+cee_setlogmask (int mask)
+{
+ if (mask != 0)
+ cee_sys_settings.mask = mask;
+ return old_setlogmask (mask);
+}
+
void openlog (const char *ident, int option, int facility)
__attribute__((alias ("cee_openlog")));
@@ -253,3 +270,6 @@ void syslog (int priority, const char *msg_format, ...)
void vsyslog (int priority, const char *msg_format, va_list ap)
__attribute__((alias ("_cee_old_vsyslog")));
+
+int setlogmask (int mask)
+ __attribute__((alias ("cee_setlogmask")));
diff --git a/lib/cee-syslog.h b/lib/cee-syslog.h
index 4f70b06..171f3ae 100644
--- a/lib/cee-syslog.h
+++ b/lib/cee-syslog.h
@@ -38,6 +38,7 @@ char *cee_format (int priority, const char *msg_format, ...);
char *cee_vformat (int priority, const char *msg_format, va_list ap);
void cee_openlog (const char *ident, int option, int facility);
+int cee_setlogmask (int mask);
void cee_syslog (int priority, const char *msg_format, ...);
void cee_vsyslog (int priority, const char *msg_format, va_list ap);