| Line |
Branch |
Exec |
Source |
| 1 |
|
|
/** |
| 2 |
|
|
* This file is part of the CernVM File System. |
| 3 |
|
|
*/ |
| 4 |
|
|
|
| 5 |
|
|
// Internal use, include only logging.h! |
| 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 |
|
|
}; |
| 113 |
|
|
|
| 114 |
|
|
const int kLogWarning = kLogStdout | kLogShowSource | kLogNormal; |
| 115 |
|
|
const int kLogInfoMsg = kLogStdout | kLogShowSource | kLogInform; |
| 116 |
|
|
const int kLogVerboseMsg = kLogStdout | kLogShowSource | kLogVerbose; |
| 117 |
|
|
|
| 118 |
|
|
struct CVMFS_EXPORT LogBufferEntry { |
| 119 |
|
19628018 |
LogBufferEntry(LogSource s, int m, const std::string &msg) |
| 120 |
|
19628018 |
: timestamp(time(NULL)), source(s), mask(m), message(msg) { } |
| 121 |
|
|
|
| 122 |
|
|
time_t timestamp; |
| 123 |
|
|
LogSource source; |
| 124 |
|
|
int mask; |
| 125 |
|
|
std::string message; |
| 126 |
|
|
}; |
| 127 |
|
|
|
| 128 |
|
|
CVMFS_EXPORT void SetLogSyslogLevel(const int level); |
| 129 |
|
|
CVMFS_EXPORT int GetLogSyslogLevel(); |
| 130 |
|
|
CVMFS_EXPORT void SetLogSyslogFacility(const int facility); |
| 131 |
|
|
CVMFS_EXPORT int GetLogSyslogFacility(); |
| 132 |
|
|
CVMFS_EXPORT void SetLogCustomFile(unsigned id, const std::string &filename); |
| 133 |
|
|
CVMFS_EXPORT void SetLogMicroSyslog(const std::string &filename); |
| 134 |
|
|
CVMFS_EXPORT std::string GetLogMicroSyslog(); |
| 135 |
|
|
CVMFS_EXPORT void SetLogMicroSyslogMaxSize(unsigned bytes); |
| 136 |
|
|
CVMFS_EXPORT void SetLogSyslogPrefix(const std::string &prefix); |
| 137 |
|
|
CVMFS_EXPORT void SetLogSyslogShowPID(bool flag); |
| 138 |
|
|
CVMFS_EXPORT void SetLogVerbosity(const LogLevels max_level); |
| 139 |
|
|
CVMFS_EXPORT void LogShutdown(); |
| 140 |
|
|
|
| 141 |
|
|
#ifdef DEBUGMSG |
| 142 |
|
|
CVMFS_EXPORT void SetLogDebugFile(const std::string &filename); |
| 143 |
|
|
CVMFS_EXPORT std::string GetLogDebugFile(); |
| 144 |
|
|
#else |
| 145 |
|
|
#define SetLogDebugFile(filename) ((void)0) |
| 146 |
|
|
#define GetLogDebugFile() (std::string("")) |
| 147 |
|
|
#endif |
| 148 |
|
|
|
| 149 |
|
|
CVMFS_EXPORT |
| 150 |
|
|
void SetAltLogFunc(void (*fn)(const LogSource source, const int mask, |
| 151 |
|
|
const char *msg)); |
| 152 |
|
|
|
| 153 |
|
|
CVMFS_EXPORT std::vector<LogBufferEntry> GetLogBuffer(); |
| 154 |
|
|
CVMFS_EXPORT void ClearLogBuffer(); |
| 155 |
|
|
|
| 156 |
|
|
CVMFS_EXPORT void PrintWarning(const std::string &message); |
| 157 |
|
|
CVMFS_EXPORT void PrintError(const std::string &message); |
| 158 |
|
|
|
| 159 |
|
|
#ifdef CVMFS_NAMESPACE_GUARD |
| 160 |
|
|
} // namespace CVMFS_NAMESPACE_GUARD |
| 161 |
|
|
#endif |
| 162 |
|
|
|
| 163 |
|
|
#endif // CVMFS_UTIL_LOGGING_INTERNAL_H_ |
| 164 |
|
|
|