From 317181e8ea1b3406919b946ca5524f8b9f34817d Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Wed, 4 Sep 2019 15:59:18 +0100 Subject: Introduce callback for logging Introduce an API for custom log handler functions. This allows libfuse applications to send messages to syslog(3) or other logging systems. See include/fuse_log.h for details. Convert libfuse from fprintf(stderr, ...) to log_fuse(level, ...). Most messages are error messages with FUSE_LOG_ERR log level. There are also some debug messages which now use the FUSE_LOG_DEBUG log level. Note that lib/mount_util.c is used by both libfuse and fusermount3. Since fusermount3 does not link against libfuse, we cannot call fuse_log() from lib/mount_util.c. This file will continue to use fprintf(stderr, ...) until someone figures out how to split it up. Signed-off-by: Stefan Hajnoczi --- lib/fuse_log.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 lib/fuse_log.c (limited to 'lib/fuse_log.c') diff --git a/lib/fuse_log.c b/lib/fuse_log.c new file mode 100644 index 0000000..09178e4 --- /dev/null +++ b/lib/fuse_log.c @@ -0,0 +1,41 @@ +/* + FUSE: Filesystem in Userspace + Copyright (C) 2019 Red Hat, Inc. + + Logging API. + + This program can be distributed under the terms of the GNU LGPLv2. + See the file COPYING.LIB +*/ + +#include "fuse_log.h" +#include "fuse_i.h" + +#include +#include + +static void default_log_func( + __attribute__(( unused )) enum fuse_log_level level, + const char *fmt, va_list ap) +{ + vfprintf(stderr, fmt, ap); +} + +static fuse_log_func_t log_func = default_log_func; + +void fuse_set_log_func(fuse_log_func_t func) +{ + if (!func) + func = default_log_func; + + log_func = func; +} + +void fuse_log(enum fuse_log_level level, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + log_func(level, fmt, ap); + va_end(ap); +} -- cgit v1.2.3