39 #ifdef CVMFS_NAMESPACE_GUARD
40 namespace CVMFS_NAMESPACE_GUARD {
43 static void LogCustom(
unsigned id,
const std::string &message);
60 pthread_mutex_t lock_debug = PTHREAD_MUTEX_INITIALIZER;
62 string *path_debug = NULL;
65 "unknown",
"cache",
"catalog",
"sql",
66 "cvmfs",
"hash",
"download",
"compress",
67 "quota",
"talk",
"monitor",
"lru",
68 "fuse stub",
"signature",
"fs traversal",
"catalog traversal",
69 "nfs maps",
"publish",
"spooler",
"concurrency",
70 "utility",
"glue buffer",
"history",
"unionfs",
71 "pathspec",
"receiver",
"upload s3",
"upload http",
72 "s3fanout",
"gc",
"dns",
"authz",
73 "reflog",
"kvstore",
"telemetry",
"curl"};
88 PTHREAD_MUTEX_INITIALIZER,
89 PTHREAD_MUTEX_INITIALIZER,
90 PTHREAD_MUTEX_INITIALIZER};
94 const char *msg) = NULL;
102 int retval = pthread_mutex_init(&lock_, NULL);
107 pthread_mutex_destroy(&lock_);
113 if (idx >= buffer_.size()) {
114 buffer_.push_back(entry);
116 buffer_[idx] = entry;
122 std::vector<LogBufferEntry> sorted_buffer;
124 for (
unsigned i = 1; i <= buffer_.size(); ++i) {
126 sorted_buffer.push_back(buffer_[idx]);
128 return sorted_buffer;
184 switch (local_facility) {
247 unsigned len = prefix.length() + 1;
281 if (filename ==
"") {
288 usyslog_fd = open(filename.c_str(), O_RDWR | O_APPEND | O_CREAT, 0600);
290 fprintf(stderr,
"could not open usyslog file %s (%d), aborting\n",
291 filename.c_str(), errno);
294 usyslog_fd1 = open((filename +
".1").c_str(), O_WRONLY | O_CREAT, 0600);
296 fprintf(stderr,
"could not open usyslog.1 file %s.1 (%d), aborting\n",
297 filename.c_str(), errno);
317 if (message.size() == 0)
return;
325 int written = write(
usyslog_fd, message.data(), message.size());
326 if ((written < 0) || (
static_cast<unsigned>(written) != message.size())) {
343 unsigned char buf[4096];
348 if (num_bytes == 0)
break;
350 assert(written == num_bytes);
351 }
while (num_bytes == 4096);
370 if (filename ==
"") {
382 fprintf(stderr,
"could not close current log file (%d), aborting\n",
388 int fd = open(filename.c_str(), O_WRONLY | O_APPEND | O_CREAT, 0600);
389 if ((fd < 0) || ((
file_debug = fdopen(fd,
"a")) == NULL)) {
390 fprintf(stderr,
"could not open debug log file %s (%d), aborting\n",
391 filename.c_str(), errno);
393 "could not open debug log file %s (%d), "
395 filename.c_str(), errno);
399 path_debug =
new string(filename);
403 if (path_debug)
return *path_debug;
424 const char *
format, va_list variadic_list) {
436 int retval = vasprintf(&msg, format, variadic_list);
440 (*alt_log_func)(source,
mask, msg);
446 pthread_mutex_lock(&lock_debug);
455 localtime_r(&rawtime, &now);
458 fprintf(
file_debug,
"(%s) %s [%02d-%02d-%04d %02d:%02d:%02d %s]\n",
459 module_names[source], msg, (now.tm_mon) + 1, now.tm_mday,
460 (now.tm_year) + 1900, now.tm_hour, now.tm_min, now.tm_sec,
465 pthread_mutex_unlock(&lock_debug);
481 fprintf(stderr,
"%s", msg);
494 ctime_r(&rawtime, fmt_time);
495 fmt_msg = string(fmt_time, 24) +
" " + fmt_msg;
496 fmt_msg.push_back(
'\n');
529 va_list variadic_list;
530 va_start(variadic_list, format);
531 vLogCvmfs(source, mask, format, variadic_list);
532 va_end(variadic_list);
564 if (filename.empty()) {
571 customlog_fds[id] = open(filename.c_str(), O_RDWR | O_APPEND | O_CREAT, 0600);
574 "could not open log file %s (%d), aborting",
575 filename.c_str(), errno);
585 static void LogCustom(
unsigned id,
const std::string &message) {
587 if (message.size() == 0)
return;
595 "could not write into log file %s (%d), aborting - lost: %s",
613 #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)
const unsigned kBufferSize
void SetLogSyslogShowPID(bool flag)
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)
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()