Coverage Report

Created: 2025-10-13 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libfuse/lib/fuse_log.c
Line
Count
Source
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
20
static bool to_syslog = false;
21
22
static void default_log_func(enum fuse_log_level level, const char *fmt, va_list ap)
23
6
{
24
6
  if (to_syslog)
25
0
    vsyslog(level, fmt, ap);
26
6
  else
27
6
    vfprintf(stderr, fmt, ap);
28
6
}
29
30
static fuse_log_func_t log_func = default_log_func;
31
32
void fuse_set_log_func(fuse_log_func_t func)
33
0
{
34
0
  if (!func)
35
0
    func = default_log_func;
36
37
0
  log_func = func;
38
0
}
39
40
void fuse_log(enum fuse_log_level level, const char *fmt, ...)
41
6
{
42
6
  va_list ap;
43
44
6
  va_start(ap, fmt);
45
6
  log_func(level, fmt, ap);
46
6
  va_end(ap);
47
6
}
48
49
void fuse_log_enable_syslog(const char *ident, int option, int facility)
50
0
{
51
0
  to_syslog = true;
52
53
0
  openlog(ident, option, facility);
54
0
}
55
56
void fuse_log_close_syslog(void)
57
0
{
58
0
  closelog();
59
0
}