Module: check_mk
Branch: master
Commit: 039f8b4fcbb9b483a57e7a6d0cde622a10b694e7
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=039f8b4fcbb9b4…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Mon Aug 8 13:45:57 2016 +0200
C++-ified logger.
---
livestatus/src/Makefile.am | 2 +-
livestatus/src/{logger.c => logger.cc} | 30 +++++++++++++-----------------
livestatus/src/logger.h | 8 --------
livestatus/src/module.cc | 2 +-
4 files changed, 15 insertions(+), 27 deletions(-)
diff --git a/livestatus/src/Makefile.am b/livestatus/src/Makefile.am
index cb06b4e..cea952e 100644
--- a/livestatus/src/Makefile.am
+++ b/livestatus/src/Makefile.am
@@ -144,7 +144,7 @@ livestatus_so_SOURCES = \
WorldNagios.cc \
auth.cc \
global_counters.cc \
- logger.c \
+ logger.cc \
mk_inventory.cc \
mk_logwatch.cc \
module.cc \
diff --git a/livestatus/src/logger.c b/livestatus/src/logger.cc
similarity index 79%
rename from livestatus/src/logger.c
rename to livestatus/src/logger.cc
index 0b12926..61db37e 100644
--- a/livestatus/src/logger.c
+++ b/livestatus/src/logger.cc
@@ -40,8 +40,8 @@ FILE *g_logfile = 0;
void open_logfile() {
g_logfile = fopen(g_logfile_path, "a");
- g_mainthread_id =
- pthread_self(); /* needed to determine main thread later */
+ // needed to determine main thread later
+ g_mainthread_id = pthread_self();
if (!g_logfile) {
logger(LG_WARN, "Cannot open logfile %s: %s", g_logfile_path,
strerror(errno));
@@ -59,28 +59,24 @@ void logger(int priority, const char *loginfo, ...) {
va_list ap;
va_start(ap, loginfo);
- /* Only the main process may use the Nagios log methods */
+ // Only the main process may use the Nagios log methods
if (!g_logfile || g_mainthread_id == pthread_self()) {
char buffer[8192];
snprintf(buffer, 20, "livestatus: ");
vsnprintf(buffer + strlen(buffer), sizeof(buffer) - strlen(buffer),
loginfo, ap);
write_to_all_logs(buffer, priority);
- } else {
- if (g_logfile) {
- /* write date/time */
- char timestring[64];
- time_t now_t = time(0);
- struct tm now;
- localtime_r(&now_t, &now);
- strftime(timestring, 64, "%F %T ", &now);
- fputs(timestring, g_logfile);
+ } else if (g_logfile) {
+ char timestring[64];
+ time_t now_t = time(0);
+ struct tm now;
+ localtime_r(&now_t, &now);
+ strftime(timestring, 64, "%F %T ", &now);
+ fputs(timestring, g_logfile);
- /* write log message */
- vfprintf(g_logfile, loginfo, ap);
- fputc('\n', g_logfile);
- fflush(g_logfile);
- }
+ vfprintf(g_logfile, loginfo, ap);
+ fputc('\n', g_logfile);
+ fflush(g_logfile);
}
va_end(ap);
}
diff --git a/livestatus/src/logger.h b/livestatus/src/logger.h
index fb0e3a9..fef8222 100644
--- a/livestatus/src/logger.h
+++ b/livestatus/src/logger.h
@@ -45,17 +45,9 @@
#define LG_ALERT LOG_INFO
#endif
-#ifdef __cplusplus
-extern "C" {
-#endif
-
void logger(int priority, const char *loginfo, ...)
__attribute__((format(printf, 2, 3)));
void open_logfile();
void close_logfile();
-#ifdef __cplusplus
-}
-#endif
-
#endif // logger_h
diff --git a/livestatus/src/module.cc b/livestatus/src/module.cc
index 22eefca..bfed2d4 100644
--- a/livestatus/src/module.cc
+++ b/livestatus/src/module.cc
@@ -88,7 +88,7 @@ char g_logfile_path[4096];
char g_mkeventd_socket_path[4096];
int g_debug_level = 0;
int g_should_terminate = false;
-pthread_t g_mainthread_id;
+extern pthread_t g_mainthread_id;
pthread_t *g_clientthread_id;
unsigned long g_max_cached_messages = 500000;
unsigned long g_max_lines_per_logfile =