libfuse: fuse-3.18.1/lib/fuse_log.c Source File

libfuse

fuse_log.c
1/*
2 FUSE: Filesystem in Userspace
3 Copyright (C) 2019 Red Hat, Inc.
4
5 Logging API.
6
7 This program can be distributed under the terms of the GNU LGPLv2.
8 See the file LGPL2.txt
9*/
10
11#include "fuse_log.h"
12
13#include <stdio.h>
14#include <stdbool.h>
15#include <syslog.h>
16#include <stdarg.h>
17
18#define MAX_SYSLOG_LINE_LEN 512
19
20static bool to_syslog = false;
21
22static void default_log_func(enum fuse_log_level level, const char *fmt, va_list ap)
23{
24 if (to_syslog)
25 vsyslog(level, fmt, ap);
26 else
27 vfprintf(stderr, fmt, ap);
28}
29
30static fuse_log_func_t log_func = default_log_func;
31
32void fuse_set_log_func(fuse_log_func_t func)
33{
34 if (!func)
35 func = default_log_func;
36
37 log_func = func;
38}
39
40void fuse_log(enum fuse_log_level level, const char *fmt, ...)
41{
42 va_list ap;
43
44 va_start(ap, fmt);
45 log_func(level, fmt, ap);
46 va_end(ap);
47}
48
49void fuse_log_enable_syslog(const char *ident, int option, int facility)
50{
51 to_syslog = true;
52
53 openlog(ident, option, facility);
54}
55
56void fuse_log_close_syslog(void)
57{
58 closelog();
59}
fuse_log_close_syslog
void fuse_log_close_syslog(void)
Definition fuse_log.c:93
fuse_log
void fuse_log(enum fuse_log_level level, const char *fmt,...)
Definition fuse_log.c:77
fuse_log_func_t
void(* fuse_log_func_t)(enum fuse_log_level level, const char *fmt, va_list ap)
Definition fuse_log.h:52
fuse_log_enable_syslog
void fuse_log_enable_syslog(const char *ident, int option, int facility)
Definition fuse_log.c:86
fuse_log_level
fuse_log_level
Definition fuse_log.h:28
fuse_set_log_func
void fuse_set_log_func(fuse_log_func_t func)
Definition fuse_log.c:69