GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/util/logging_internal.h
Date: 2026-08-30 02:40:36
Exec Total Coverage
Lines: 4 6 66.7%
Branches: 0 0 -%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5 // Internal use, included only by logging.h and logging.cc!
6
7 #ifndef CVMFS_UTIL_LOGGING_INTERNAL_H_
8 #define CVMFS_UTIL_LOGGING_INTERNAL_H_
9
10 #include <cstdarg>
11 #include <ctime>
12 #include <string>
13 #include <vector>
14
15 #include "util/export.h"
16
17 #ifdef CVMFS_NAMESPACE_GUARD
18 namespace CVMFS_NAMESPACE_GUARD {
19 #endif
20
21 enum LogFacilities {
22 kLogDebug = 0x01,
23 kLogStdout = 0x02,
24 kLogStderr = 0x04,
25 kLogSyslog = 0x08,
26 kLogSyslogWarn = 0x10,
27 kLogSyslogErr = 0x20,
28 kLogCustom0 = 0x40,
29 kLogCustom1 = 0x80,
30 kLogCustom2 = 0x100,
31 };
32
33 /**
34 * Default logging facilities
35 *
36 * Classes which are reused in different parts of CVMFS may need to log to
37 * different facilities. For example, in the client logging should be done
38 * to the system log, while in cvmfs_swissknife it should be done to stdout.
39 *
40 * When logging to the default facilities:
41 *
42 * LogCvmfs(kLogCvmfs, DefaultLogging::info, ...)
43 *
44 * the facilities can be changed as needed, without modifying the caller code.
45 *
46 * The default facilities are kLogStdout and kLogStderr.
47 */
48 struct CVMFS_EXPORT DefaultLogging {
49 /**
50 * Change the default logging facilities
51 */
52 static void Set(LogFacilities info, LogFacilities error);
53
54 static LogFacilities info; // default kLogStdout
55 static LogFacilities error; // default kLogStderr
56 };
57
58 enum LogFlags {
59 kLogNoLinebreak = 0x200,
60 kLogShowSource = 0x400,
61 kLogSensitive = 0x800, ///< Don't add the line to the memory log buffer
62 };
63
64 enum LogLevels {
65 kLogLevel0 = 0x01000,
66 kLogNormal = 0x02000,
67 kLogInform = 0x04000,
68 kLogVerbose = 0x08000,
69 kLogNone = 0x10000,
70 };
71
72 /**
73 * The log facilities, flags, and levels occupy disjoint bit ranges of the
74 * same integer log mask and are meant to be combined with bitwise OR.
75 * C++20 deprecates bitwise operations between different enumeration types,
76 * so spell out the intended integer combination once, centrally.
77 */
78 436 inline int operator|(LogFacilities facility, LogFlags flag) {
79 436 return static_cast<int>(facility) | static_cast<int>(flag);
80 }
81 inline int operator|(LogFlags flag, LogFacilities facility) {
82 return static_cast<int>(flag) | static_cast<int>(facility);
83 }
84 inline int operator|(LogFacilities facility, LogLevels level) {
85 return static_cast<int>(facility) | static_cast<int>(level);
86 }
87 inline int operator|(LogLevels level, LogFacilities facility) {
88 return static_cast<int>(level) | static_cast<int>(facility);
89 }
90 inline int operator|(LogFlags flag, LogLevels level) {
91 return static_cast<int>(flag) | static_cast<int>(level);
92 }
93 inline int operator|(LogLevels level, LogFlags flag) {
94 return static_cast<int>(level) | static_cast<int>(flag);
95 }
96
97 /**
98 * Changes in this enum must be done in logging.cc as well!
99 * (see const char *module_names[] = {....})
100 */
101 enum LogSource {
102 kLogCache = 1,
103 kLogCatalog,
104 kLogSql,
105 kLogCvmfs,
106 kLogHash,
107 kLogDownload,
108 kLogCompress,
109 kLogQuota,
110 kLogTalk,
111 kLogMonitor,
112 kLogLru,
113 kLogFuse,
114 kLogSignature,
115 kLogFsTraversal,
116 kLogCatalogTraversal,
117 kLogNfsMaps,
118 kLogPublish,
119 kLogSpooler,
120 kLogConcurrency,
121 kLogUtility,
122 kLogGlueBuffer,
123 kLogHistory,
124 kLogUnionFs,
125 kLogPathspec,
126 kLogReceiver,
127 kLogUploadS3,
128 kLogUploadGateway,
129 kLogS3Fanout,
130 kLogGc,
131 kLogDns,
132 kLogAuthz,
133 kLogReflog,
134 kLogKvStore,
135 kLogTelemetry,
136 kLogCurl,
137 kLogBundleMgr
138 };
139
140 /**
141 * The static_cast selects the built-in operator| for the first pair of
142 * operands, which keeps these three integral constant expressions. Without
143 * it the overloads above make them dynamically initialised globals.
144 */
145 const int kLogWarning =
146 static_cast<int>(kLogStdout) | kLogShowSource | kLogNormal; // NOLINT
147 const int kLogInfoMsg =
148 static_cast<int>(kLogStdout) | kLogShowSource | kLogInform; // NOLINT
149 const int kLogVerboseMsg =
150 static_cast<int>(kLogStdout) | kLogShowSource | kLogVerbose; // NOLINT
151
152 struct CVMFS_EXPORT LogBufferEntry {
153 47665521 LogBufferEntry(LogSource s, int m, const std::string &msg)
154 47665521 : timestamp(time(NULL)), source(s), mask(m), message(msg) { }
155
156 time_t timestamp;
157 LogSource source;
158 int mask;
159 std::string message;
160 };
161
162 CVMFS_EXPORT void SetLogSyslogLevel(const int level);
163 CVMFS_EXPORT int GetLogSyslogLevel();
164 CVMFS_EXPORT void SetLogSyslogFacility(const int facility);
165 CVMFS_EXPORT int GetLogSyslogFacility();
166 CVMFS_EXPORT void SetLogCustomFile(unsigned id, const std::string &filename);
167 CVMFS_EXPORT void SetLogMicroSyslog(const std::string &filename);
168 CVMFS_EXPORT std::string GetLogMicroSyslog();
169 CVMFS_EXPORT void SetLogMicroSyslogMaxSize(unsigned bytes);
170 CVMFS_EXPORT void SetLogSyslogPrefix(const std::string &prefix);
171 CVMFS_EXPORT void SetLogSyslogShowPID(bool flag);
172 CVMFS_EXPORT void SetLogVerbosity(const LogLevels max_level);
173 CVMFS_EXPORT void LogShutdown();
174
175 #ifdef DEBUGMSG
176 CVMFS_EXPORT void SetLogDebugFile(const std::string &filename);
177 CVMFS_EXPORT std::string GetLogDebugFile();
178 #else
179 #define SetLogDebugFile(filename) ((void)0)
180 #define GetLogDebugFile() (std::string(""))
181 #endif
182
183 CVMFS_EXPORT
184 void SetAltLogFunc(void (*fn)(const LogSource source, const int mask,
185 const char *msg));
186
187 CVMFS_EXPORT std::vector<LogBufferEntry> GetLogBuffer();
188 CVMFS_EXPORT void ClearLogBuffer();
189
190 CVMFS_EXPORT void PrintWarning(const std::string &message);
191 CVMFS_EXPORT void PrintError(const std::string &message);
192
193 #ifdef CVMFS_NAMESPACE_GUARD
194 } // namespace CVMFS_NAMESPACE_GUARD
195 #endif
196
197 #endif // CVMFS_UTIL_LOGGING_INTERNAL_H_
198
199