38 #ifdef CVMFS_NAMESPACE_GUARD
39 namespace CVMFS_NAMESPACE_GUARD {
42 static void LogCustom(
unsigned id,
const std::string &message);
59 pthread_mutex_t lock_debug = PTHREAD_MUTEX_INITIALIZER;
61 string *path_debug = NULL;
64 "unknown",
"cache",
"catalog",
"sql",
65 "cvmfs",
"hash",
"download",
"compress",
66 "quota",
"talk",
"monitor",
"lru",
67 "fuse stub",
"signature",
"fs traversal",
"catalog traversal",
68 "nfs maps",
"publish",
"spooler",
"concurrency",
69 "utility",
"glue buffer",
"history",
"unionfs",
70 "pathspec",
"receiver",
"upload s3",
"upload http",
71 "s3fanout",
"gc",
"dns",
"authz",
72 "reflog",
"kvstore",
"telemetry",
"curl"};
87 PTHREAD_MUTEX_INITIALIZER,
88 PTHREAD_MUTEX_INITIALIZER};
92 const char *msg) = NULL;
100 const int retval = pthread_mutex_init(&lock_, NULL);
109 if (idx >= buffer_.size()) {
110 buffer_.push_back(entry);
112 buffer_[idx] = entry;
118 std::vector<LogBufferEntry> sorted_buffer;
120 for (
unsigned i = 1; i <= buffer_.size(); ++i) {
122 sorted_buffer.push_back(buffer_[idx]);
124 return sorted_buffer;
180 switch (local_facility) {
244 const unsigned len = prefix.length() + 1;
276 if (filename ==
"") {
283 usyslog_fd = open(filename.c_str(), O_RDWR | O_APPEND | O_CREAT, 0600);
285 fprintf(stderr,
"could not open usyslog file %s (%d), aborting\n",
286 filename.c_str(), errno);
289 usyslog_fd1 = open((filename +
".1").c_str(), O_WRONLY | O_CREAT, 0600);
291 fprintf(stderr,
"could not open usyslog.1 file %s.1 (%d), aborting\n",
292 filename.c_str(), errno);
313 if (message.size() == 0)
322 const int written = write(
usyslog_fd, message.data(), message.size());
323 if ((written < 0) || (
static_cast<unsigned>(written) != message.size())) {
340 unsigned char buf[4096];
347 const int written = write(
usyslog_fd1, buf, num_bytes);
348 assert(written == num_bytes);
349 }
while (num_bytes == 4096);
368 if (filename ==
"") {
380 fprintf(stderr,
"could not close current log file (%d), aborting\n",
386 const int fd = open(filename.c_str(), O_WRONLY | O_APPEND | O_CREAT, 0600);
387 if ((fd < 0) || ((
file_debug = fdopen(fd,
"a")) == NULL)) {
388 fprintf(stderr,
"could not open debug log file %s (%d), aborting\n",
389 filename.c_str(), errno);
391 "could not open debug log file %s (%d), "
393 filename.c_str(), errno);
397 path_debug =
new string(filename);
423 va_list variadic_list) {
438 const int retval = vasprintf(&msg, format, variadic_list);
448 pthread_mutex_lock(&lock_debug);
458 localtime_r(&rawtime, &now);
462 fprintf(
file_debug,
"(%s) %s [%02d-%02d-%04d %02d:%02d:%02d %s]\n",
463 module_names[source], msg, (now.tm_mon) + 1, now.tm_mday,
464 (now.tm_year) + 1900, now.tm_hour, now.tm_min, now.tm_sec,
470 pthread_mutex_unlock(&lock_debug);
489 fprintf(stderr,
"%s", msg);
491 fprintf(stderr,
"\n");
504 ctime_r(&rawtime, fmt_time);
505 fmt_msg = string(fmt_time, 24) +
" " + fmt_msg;
506 fmt_msg.push_back(
'\n');
546 va_list variadic_list;
547 va_start(variadic_list, format);
548 vLogCvmfs(source, mask, format, variadic_list);
549 va_end(variadic_list);
577 if (filename.empty()) {
584 customlog_fds[id] = open(filename.c_str(), O_RDWR | O_APPEND | O_CREAT, 0600);
587 "could not open log file %s (%d), aborting", filename.c_str(),
598 static void LogCustom(
unsigned id,
const std::string &message) {
600 if (message.size() == 0)
606 const bool retval_b =
610 "could not write into log file %s (%d), aborting - lost: %s",
628 #ifdef CVMFS_NAMESPACE_GUARD
std::vector< LogBufferEntry > GetLogBuffer()
void SetLogSyslogFacility(const int local_facility)
void SetLogVerbosity(const LogLevels max_level)
const char * module_names[]
pthread_mutex_t customlog_locks[]
void SetLogSyslogLevel(const int level)
static void LogCustom(unsigned id, const std::string &message)
CVMFS_EXPORT const LogSource const int mask
const unsigned kBufferSize
void SetLogSyslogShowPID(bool flag)
CVMFS_EXPORT const LogSource source
string * customlog_dests[]
std::vector< LogBufferEntry > GetBuffer()
CVMFS_EXPORT void vLogCvmfs(const LogSource source, const int mask, const char *format, va_list variadic_list)
static void Set(LogFacilities info, LogFacilities error)
static void LogMicroSyslog(const std::string &message)
bool SafeWrite(int fd, const void *buf, size_t nbyte)
void SetLogMicroSyslogMaxSize(unsigned bytes)
assert((mem||(size==0))&&"Out Of Memory")
void Append(const LogBufferEntry &entry)
void SetAltLogFunc(void(*fn)(const LogSource source, const int mask, const char *msg))
void SetLogMicroSyslog(const std::string &filename)
#define SetLogDebugFile(filename)
pthread_mutex_t lock_stdout
static void(* alt_log_func)(const LogSource source, const int mask, const char *msg)
#define GetLogDebugFile()
Don't add the line to the memory log buffer.
pthread_mutex_t lock_usyslock
void SetLogCustomFile(unsigned id, const std::string &filename)
std::string GetLogMicroSyslog()
void PrintWarning(const string &message)
CVMFS_EXPORT const LogSource const int const char * format
void SetLogSyslogPrefix(const std::string &prefix)
void PrintError(const string &message)
static LogFacilities info
static LogFacilities error
pthread_mutex_t lock_stderr
const unsigned kMaxCustomlog
std::vector< LogBufferEntry > buffer_
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)
int GetLogSyslogFacility()