GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/util/logging_internal.h
Date: 2026-06-28 02:36:10
Exec Total Coverage
Lines: 2 2 100.0%
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 * Changes in this enum must be done in logging.cc as well!
74 * (see const char *module_names[] = {....})
75 */
76 enum LogSource {
77 kLogCache = 1,
78 kLogCatalog,
79 kLogSql,
80 kLogCvmfs,
81 kLogHash,
82 kLogDownload,
83 kLogCompress,
84 kLogQuota,
85 kLogTalk,
86 kLogMonitor,
87 kLogLru,
88 kLogFuse,
89 kLogSignature,
90 kLogFsTraversal,
91 kLogCatalogTraversal,
92 kLogNfsMaps,
93 kLogPublish,
94 kLogSpooler,
95 kLogConcurrency,
96 kLogUtility,
97 kLogGlueBuffer,
98 kLogHistory,
99 kLogUnionFs,
100 kLogPathspec,
101 kLogReceiver,
102 kLogUploadS3,
103 kLogUploadGateway,
104 kLogS3Fanout,
105 kLogGc,
106 kLogDns,
107 kLogAuthz,
108 kLogReflog,
109 kLogKvStore,
110 kLogTelemetry,
111 kLogCurl,
112 kLogBundleMgr
113 };
114
115 const int kLogWarning = kLogStdout | kLogShowSource | kLogNormal;
116 const int kLogInfoMsg = kLogStdout | kLogShowSource | kLogInform;
117 const int kLogVerboseMsg = kLogStdout | kLogShowSource | kLogVerbose;
118
119 struct CVMFS_EXPORT LogBufferEntry {
120 39024351 LogBufferEntry(LogSource s, int m, const std::string &msg)
121 39024351 : timestamp(time(NULL)), source(s), mask(m), message(msg) { }
122
123 time_t timestamp;
124 LogSource source;
125 int mask;
126 std::string message;
127 };
128
129 CVMFS_EXPORT void SetLogSyslogLevel(const int level);
130 CVMFS_EXPORT int GetLogSyslogLevel();
131 CVMFS_EXPORT void SetLogSyslogFacility(const int facility);
132 CVMFS_EXPORT int GetLogSyslogFacility();
133 CVMFS_EXPORT void SetLogCustomFile(unsigned id, const std::string &filename);
134 CVMFS_EXPORT void SetLogMicroSyslog(const std::string &filename);
135 CVMFS_EXPORT std::string GetLogMicroSyslog();
136 CVMFS_EXPORT void SetLogMicroSyslogMaxSize(unsigned bytes);
137 CVMFS_EXPORT void SetLogSyslogPrefix(const std::string &prefix);
138 CVMFS_EXPORT void SetLogSyslogShowPID(bool flag);
139 CVMFS_EXPORT void SetLogVerbosity(const LogLevels max_level);
140 CVMFS_EXPORT void LogShutdown();
141
142 #ifdef DEBUGMSG
143 CVMFS_EXPORT void SetLogDebugFile(const std::string &filename);
144 CVMFS_EXPORT std::string GetLogDebugFile();
145 #else
146 #define SetLogDebugFile(filename) ((void)0)
147 #define GetLogDebugFile() (std::string(""))
148 #endif
149
150 CVMFS_EXPORT
151 void SetAltLogFunc(void (*fn)(const LogSource source, const int mask,
152 const char *msg));
153
154 CVMFS_EXPORT std::vector<LogBufferEntry> GetLogBuffer();
155 CVMFS_EXPORT void ClearLogBuffer();
156
157 CVMFS_EXPORT void PrintWarning(const std::string &message);
158 CVMFS_EXPORT void PrintError(const std::string &message);
159
160 #ifdef CVMFS_NAMESPACE_GUARD
161 } // namespace CVMFS_NAMESPACE_GUARD
162 #endif
163
164 #endif // CVMFS_UTIL_LOGGING_INTERNAL_H_
165
166