From 537e00d5b56afa9b3d03930885567ac322610202 Mon Sep 17 00:00:00 2001 From: Moritz Rosenthal Date: Wed, 30 Mar 2016 16:37:35 +0200 Subject: [PATCH] Logging to syslog is standard in Linux environment and should be used. --- src/common/capwap_logging.c | 20 ++++++++++++++++++-- src/common/capwap_logging.h | 9 ++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/common/capwap_logging.c b/src/common/capwap_logging.c index 7a91055..297c53a 100644 --- a/src/common/capwap_logging.c +++ b/src/common/capwap_logging.c @@ -40,6 +40,9 @@ void capwap_logging_init() { #ifdef CAPWAP_MULTITHREADING_ENABLE capwap_lock_init(&l_loglock); #endif +#ifdef LOG_TO_SYSLOG + openlog("capwap", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_DAEMON); +#endif } /* */ @@ -47,6 +50,9 @@ void capwap_logging_close() { #ifdef CAPWAP_MULTITHREADING_ENABLE capwap_lock_destroy(&l_loglock); #endif +#ifdef LOG_TO_SYSLOG + closelog(); +#endif } /* */ @@ -107,6 +113,16 @@ void capwap_logging_disable_console(void) { /* */ #ifdef ENABLE_LOGGING +void __log_syslog(int level, const char* format, ...) +{ + int errsv = errno; + va_list args; + va_start(args, format); + vsyslog(level, format, args); + va_end(args); + errno = errsv; +} + void __log_printf(int level, const char* format, ...) { int errsv = errno; @@ -143,8 +159,8 @@ void __log_printf(int level, const char* format, ...) void __log_hexdump(int level, const char *title, const unsigned char *data, size_t len) { - int errsv = errno; - char prefix[256]; + int errsv = errno; + char prefix[256]; if (level > logginglevel) return; diff --git a/src/common/capwap_logging.h b/src/common/capwap_logging.h index 9d0ab0b..4d83ba8 100644 --- a/src/common/capwap_logging.h +++ b/src/common/capwap_logging.h @@ -2,6 +2,7 @@ #define __CAPWAP_LOGGING_HEADER__ #include +#define LOG_TO_SYSLOG /* Logging level */ #define LOG_NONE -1 @@ -23,6 +24,8 @@ void capwap_logging_disable_console(void); void __log_printf(int level, const char *format, ...) __attribute__ ((__format__ (__printf__, 2, 3))); void __log_hexdump(int level, const char *title, const unsigned char *data, size_t len); +void __log_syslog(int level, const char* format, ...) + __attribute__ ((__format__ (__printf__, 2, 3))); #ifdef DISABLE_LOGGING_DEBUG @@ -39,11 +42,15 @@ void __log_hexdump(int level, const char *title, const unsigned char *data, size #else +#ifdef LOG_TO_SYSLOG +#define log_printf(level, f, args...) \ + __log_syslog((level), (f), ##args) +#else #define log_printf(level, f, args...) \ __log_printf((level), (f), ##args) +#endif #define log_hexdump(level, title, data, len) \ __log_hexdump((level), (title), (data), (len)) - #endif #else