GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/nfs4/logging.cc
Date: 2026-11-01 02:41:19
Exec Total Coverage
Lines: 23 36 63.9%
Branches: 10 26 38.5%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5 #include "nfs4/logging.h"
6
7 #include <sys/time.h>
8 #include <syslog.h>
9
10 #include <cstdarg>
11 #include <cstdio>
12 #include <cstdlib>
13
14 namespace nfs4 {
15
16 namespace {
17
18 31 FILE *DebugStream() {
19 31 const char *debug = getenv("CVMFS_NFS4_DEBUG");
20
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 if (debug == NULL)
21 31 return NULL;
22 // A path redirects the trace, e.g. for a daemon without stderr
23 ✗ if (debug[0] == '/') {
24 ✗ FILE *f = fopen(debug, "a");
25 ✗ if (f) {
26 ✗ setvbuf(f, NULL, _IOLBF, 0);
27 ✗ return f;
28 }
29 }
30 ✗ return stderr;
31 }
32
33 9207 void DefaultSink(LogLevel level, const char *message) {
34
4/8
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 9176 times.
✓ Branch 3 taken 31 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 31 times.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
9207 static FILE *debug = DebugStream();
35
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9207 times.
9207 if (debug) {
36 struct timeval now;
37 ✗ gettimeofday(&now, NULL);
38 ✗ fprintf(debug, "%ld.%03d (nfs4) %s\n", static_cast<long>(now.tv_sec), // NOLINT
39 ✗ static_cast<int>(now.tv_usec / 1000), message);
40 }
41
3/4
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9114 times.
9207 switch (level) {
42 62 case kLogLevelInfo:
43 62 syslog(LOG_INFO, "(nfs4) %s", message);
44 62 break;
45 31 case kLogLevelWarn:
46 31 syslog(LOG_WARNING, "(nfs4) %s", message);
47 31 break;
48 ✗ case kLogLevelError:
49 ✗ syslog(LOG_ERR, "(nfs4) %s", message);
50 ✗ break;
51 9114 default:
52 9114 break;
53 }
54 9207 }
55
56 LogSink g_sink = DefaultSink;
57
58 } // anonymous namespace
59
60 ✗ void SetLogSink(LogSink sink) { g_sink = sink ? sink : DefaultSink; }
61
62 9207 void Log(LogLevel level, const char *format, ...) {
63 char buf[1024];
64 va_list args;
65 9207 va_start(args, format);
66 9207 vsnprintf(buf, sizeof(buf), format, args);
67 9207 va_end(args);
68
1/2
✓ Branch 1 taken 9207 times.
✗ Branch 2 not taken.
9207 g_sink(level, buf);
69 9207 }
70
71 } // namespace nfs4
72