switch to more a syslog like logging style
This commit is contained in:
parent
9572de350a
commit
cadbfa3d7e
12
src/ac/ac.c
12
src/ac/ac.c
@ -214,20 +214,20 @@ static int ac_parsing_configuration_1_0(config_t* config) {
|
||||
/* Logging configuration */
|
||||
if (config_lookup_bool(config, "logging.enable", &configBool) == CONFIG_TRUE) {
|
||||
if (!configBool) {
|
||||
capwap_logging_verboselevel(CAPWAP_LOGGING_NONE);
|
||||
capwap_logging_verboselevel(LOG_NONE);
|
||||
capwap_logging_disable_allinterface();
|
||||
} else {
|
||||
if (config_lookup_string(config, "logging.level", &configString) == CONFIG_TRUE) {
|
||||
if (!strcmp(configString, "fatal")) {
|
||||
capwap_logging_verboselevel(CAPWAP_LOGGING_FATAL);
|
||||
capwap_logging_verboselevel(LOG_EMERG);
|
||||
} else if (!strcmp(configString, "error")) {
|
||||
capwap_logging_verboselevel(CAPWAP_LOGGING_ERROR);
|
||||
capwap_logging_verboselevel(LOG_ERR);
|
||||
} else if (!strcmp(configString, "warning")) {
|
||||
capwap_logging_verboselevel(CAPWAP_LOGGING_WARNING);
|
||||
capwap_logging_verboselevel(LOG_WARNING);
|
||||
} else if (!strcmp(configString, "info")) {
|
||||
capwap_logging_verboselevel(CAPWAP_LOGGING_INFO);
|
||||
capwap_logging_verboselevel(LOG_INFO);
|
||||
} else if (!strcmp(configString, "debug")) {
|
||||
capwap_logging_verboselevel(CAPWAP_LOGGING_DEBUG);
|
||||
capwap_logging_verboselevel(LOG_DEBUG);
|
||||
} else {
|
||||
capwap_logging_error("Invalid configuration file, unknown logging.level value");
|
||||
return 0;
|
||||
|
@ -10,7 +10,7 @@ static capwap_lock_t l_loglock;
|
||||
#endif
|
||||
|
||||
/* */
|
||||
static int logginglevel = CAPWAP_LOGGING_NONE;
|
||||
static int logginglevel = LOG_NONE;
|
||||
static int loggingoutputstdout = 0;
|
||||
static int loggingoutputstderr = 0;
|
||||
|
||||
@ -50,7 +50,7 @@ void capwap_logging_close() {
|
||||
}
|
||||
|
||||
/* */
|
||||
void capwap_logging_verboselevel(unsigned int level) {
|
||||
void capwap_logging_verboselevel(int level) {
|
||||
#ifdef CAPWAP_MULTITHREADING_ENABLE
|
||||
capwap_lock_enter(&l_loglock);
|
||||
#endif
|
||||
@ -119,7 +119,7 @@ void capwap_logging_printf(int level, const char* format, ...)
|
||||
capwap_lock_enter(&l_loglock);
|
||||
#endif
|
||||
|
||||
if ((logginglevel != CAPWAP_LOGGING_NONE) && (level <= logginglevel)) {
|
||||
if (level <= logginglevel) {
|
||||
prefix_logging(level, prefix);
|
||||
|
||||
if (loggingoutputstdout || loggingoutputstderr) {
|
||||
@ -146,8 +146,7 @@ void capwap_logging_hexdump(int level, const char *title, const unsigned char *d
|
||||
int errsv = errno;
|
||||
char prefix[256];
|
||||
|
||||
if ((logginglevel == CAPWAP_LOGGING_NONE) ||
|
||||
(level > logginglevel))
|
||||
if (level > logginglevel)
|
||||
return;
|
||||
|
||||
#ifdef CAPWAP_MULTITHREADING_ENABLE
|
||||
|
@ -1,27 +1,17 @@
|
||||
#ifndef __CAPWAP_LOGGING_HEADER__
|
||||
#define __CAPWAP_LOGGING_HEADER__
|
||||
|
||||
/* Logging level */
|
||||
#define CAPWAP_LOGGING_NONE 0
|
||||
#define CAPWAP_LOGGING_FATAL 1
|
||||
#define CAPWAP_LOGGING_ERROR 2
|
||||
#define CAPWAP_LOGGING_WARNING 3
|
||||
#define CAPWAP_LOGGING_INFO 4
|
||||
#define CAPWAP_LOGGING_DEBUG 5
|
||||
#include <syslog.h>
|
||||
|
||||
#define LOG_NONE CAPWAP_LOGGING_NONE
|
||||
#define LOG_FATAL CAPWAP_LOGGING_FATAL
|
||||
#define LOG_ERROR CAPWAP_LOGGING_ERROR
|
||||
#define LOG_WARNING CAPWAP_LOGGING_WARNING
|
||||
#define LOG_INFO CAPWAP_LOGGING_INFO
|
||||
#define LOG_DEBUG CAPWAP_LOGGING_DEBUG
|
||||
/* Logging level */
|
||||
#define LOG_NONE -1
|
||||
|
||||
/* Logging initialize function */
|
||||
void capwap_logging_init();
|
||||
void capwap_logging_close();
|
||||
|
||||
/* */
|
||||
void capwap_logging_verboselevel(unsigned int level);
|
||||
void capwap_logging_verboselevel(int level);
|
||||
|
||||
/* */
|
||||
void capwap_logging_disable_allinterface();
|
||||
@ -30,26 +20,31 @@ void capwap_logging_disable_console(void);
|
||||
|
||||
/* */
|
||||
#ifdef ENABLE_LOGGING
|
||||
void capwap_logging_printf(int level, const char *format, ...);
|
||||
void capwap_logging_hexdump(int level, const char *title, const unsigned char *data, size_t len);
|
||||
void log_printf(int level, const char *format, ...);
|
||||
void log_hexdump(int level, const char *title, const unsigned char *data, size_t len);
|
||||
#else
|
||||
#define capwap_logging_printf(l, f, args...) do { } while (0)
|
||||
#define capwap_logging_hexdump(l, t, d, len) do { } while (0)
|
||||
#define log_printf(l, f, args...) do { } while (0)
|
||||
#define log_hexdump(l, t, d, len) do { } while (0)
|
||||
#endif
|
||||
|
||||
#define log_printf capwap_logging_printf
|
||||
#define log_hexdump capwap_logging_hexdump
|
||||
#define capwap_logging_printf log_printf
|
||||
#define capwap_logging_hexdump log_hexdump
|
||||
|
||||
/* */
|
||||
#define capwap_logging_fatal(f, args...) capwap_logging_printf(CAPWAP_LOGGING_FATAL, f, ##args)
|
||||
#define capwap_logging_error(f, args...) capwap_logging_printf(CAPWAP_LOGGING_ERROR, f, ##args)
|
||||
#define capwap_logging_warning(f, args...) capwap_logging_printf(CAPWAP_LOGGING_WARNING, f, ##args)
|
||||
#define capwap_logging_info(f, args...) capwap_logging_printf(CAPWAP_LOGGING_INFO, f, ##args)
|
||||
#define capwap_logging_fatal(f, args...) \
|
||||
log_printf(LOG_EMERG, f, ##args)
|
||||
#define capwap_logging_error(f, args...) \
|
||||
log_printf(LOG_ERR, f, ##args)
|
||||
#define capwap_logging_warning(f, args...) \
|
||||
log_printf(LOG_WARNING, f, ##args)
|
||||
#define capwap_logging_info(f, args...) \
|
||||
log_printf(LOG_INFO, f, ##args)
|
||||
|
||||
#ifdef DISABLE_LOGGING_DEBUG
|
||||
#define capwap_logging_debug(f, args...)
|
||||
#else
|
||||
#define capwap_logging_debug(f, args...) capwap_logging_printf(CAPWAP_LOGGING_DEBUG, f, ##args)
|
||||
#define capwap_logging_debug(f, args...) \
|
||||
log_printf(LOG_DEBUG, f, ##args)
|
||||
#endif
|
||||
|
||||
#endif /* __CAPWAP_LOGGING_HEADER__ */
|
||||
|
@ -814,20 +814,20 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
|
||||
/* Logging configuration */
|
||||
if (config_lookup_bool(config, "logging.enable", &configBool) == CONFIG_TRUE) {
|
||||
if (!configBool) {
|
||||
capwap_logging_verboselevel(CAPWAP_LOGGING_NONE);
|
||||
capwap_logging_verboselevel(LOG_NONE);
|
||||
capwap_logging_disable_allinterface();
|
||||
} else {
|
||||
if (config_lookup_string(config, "logging.level", &configString) == CONFIG_TRUE) {
|
||||
if (!strcmp(configString, "fatal")) {
|
||||
capwap_logging_verboselevel(CAPWAP_LOGGING_FATAL);
|
||||
capwap_logging_verboselevel(LOG_EMERG);
|
||||
} else if (!strcmp(configString, "error")) {
|
||||
capwap_logging_verboselevel(CAPWAP_LOGGING_ERROR);
|
||||
capwap_logging_verboselevel(LOG_ERR);
|
||||
} else if (!strcmp(configString, "warning")) {
|
||||
capwap_logging_verboselevel(CAPWAP_LOGGING_WARNING);
|
||||
capwap_logging_verboselevel(LOG_WARNING);
|
||||
} else if (!strcmp(configString, "info")) {
|
||||
capwap_logging_verboselevel(CAPWAP_LOGGING_INFO);
|
||||
capwap_logging_verboselevel(LOG_INFO);
|
||||
} else if (!strcmp(configString, "debug")) {
|
||||
capwap_logging_verboselevel(CAPWAP_LOGGING_DEBUG);
|
||||
capwap_logging_verboselevel(LOG_DEBUG);
|
||||
} else {
|
||||
capwap_logging_error("Invalid configuration file, unknown logging.level value");
|
||||
return 0;
|
||||
@ -1377,7 +1377,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
/* Init logging */
|
||||
capwap_logging_init();
|
||||
capwap_logging_verboselevel(CAPWAP_LOGGING_ERROR);
|
||||
capwap_logging_verboselevel(LOG_ERR);
|
||||
capwap_logging_enable_console(1);
|
||||
|
||||
/* Init capwap */
|
||||
|
Loading…
Reference in New Issue
Block a user