From 117ed2071b9471f40b9c782bb471568b87b7ec6a Mon Sep 17 00:00:00 2001 From: albfan Date: Sat, 22 Aug 2015 11:07:13 +0200 Subject: [PATCH] Parse text log level closes #42 --- src/ctl/ctl.h | 29 +---------------------------- src/ctl/sinkctl.c | 2 +- src/ctl/wifictl.c | 2 +- src/dhcp/dhcp.c | 2 +- src/miracled.c | 2 +- src/shared/shl_log.c | 27 +++++++++++++++++++++++++++ src/shared/shl_log.h | 2 ++ src/wifi/wifid.c | 4 ++-- 8 files changed, 36 insertions(+), 34 deletions(-) diff --git a/src/ctl/ctl.h b/src/ctl/ctl.h index 588bfab..40e49ec 100644 --- a/src/ctl/ctl.h +++ b/src/ctl/ctl.h @@ -27,6 +27,7 @@ #include #include #include "shl_dlist.h" +#include "shl_log.h" #ifndef CTL_CTL_H #define CTL_CTL_H @@ -123,34 +124,6 @@ extern int cli_max_sev; void cli_printv(const char *fmt, va_list args); void cli_printf(const char *fmt, ...); -enum { -#ifndef LOG_FATAL - LOG_FATAL = 0, -#endif -#ifndef LOG_ALERT - LOG_ALERT = 1, -#endif -#ifndef LOG_CRITICAL - LOG_CRITICAL = 2, -#endif -#ifndef LOG_ERROR - LOG_ERROR = 3, -#endif -#ifndef LOG_WARNING - LOG_WARNING = 4, -#endif -#ifndef LOG_NOTICE - LOG_NOTICE = 5, -#endif -#ifndef LOG_INFO - LOG_INFO = 6, -#endif -#ifndef LOG_DEBUG - LOG_DEBUG = 7, -#endif - LOG_SEV_NUM, -}; - #define cli_log(_fmt, ...) \ cli_printf(_fmt "\n", ##__VA_ARGS__) #define cli_log_fn(_fmt, ...) \ diff --git a/src/ctl/sinkctl.c b/src/ctl/sinkctl.c index 78e3c78..24d461e 100644 --- a/src/ctl/sinkctl.c +++ b/src/ctl/sinkctl.c @@ -703,7 +703,7 @@ static int parse_argv(int argc, char *argv[]) puts(PACKAGE_STRING); return 0; case ARG_LOG_LEVEL: - cli_max_sev = atoi(optarg); + cli_max_sev = log_parse_arg(optarg); break; case ARG_AUDIO: gst_audio_en = atoi(optarg); diff --git a/src/ctl/wifictl.c b/src/ctl/wifictl.c index 47ba9d8..f8bf7e5 100644 --- a/src/ctl/wifictl.c +++ b/src/ctl/wifictl.c @@ -514,7 +514,7 @@ static int parse_argv(int argc, char *argv[]) puts(PACKAGE_STRING); return 0; case ARG_LOG_LEVEL: - cli_max_sev = atoi(optarg); + cli_max_sev = log_parse_arg(optarg); break; case '?': return -EINVAL; diff --git a/src/dhcp/dhcp.c b/src/dhcp/dhcp.c index 5e74e8a..366ca47 100644 --- a/src/dhcp/dhcp.c +++ b/src/dhcp/dhcp.c @@ -818,7 +818,7 @@ static int parse_argv(int argc, char *argv[]) puts(PACKAGE_STRING); return 0; case ARG_LOG_LEVEL: - log_max_sev = atoi(optarg); + log_max_sev = log_parse_arg(optarg); break; case ARG_LOG_TIME: log_init_time(); diff --git a/src/miracled.c b/src/miracled.c index 0a03ad4..c08fffe 100644 --- a/src/miracled.c +++ b/src/miracled.c @@ -99,7 +99,7 @@ static int parse_argv(int argc, char *argv[]) puts(PACKAGE_STRING); return 0; case ARG_LOG_LEVEL: - log_max_sev = atoi(optarg); + log_max_sev = log_parse_arg(optarg); break; case ARG_LOG_TIME: log_init_time(); diff --git a/src/shared/shl_log.c b/src/shared/shl_log.c index 3e081fe..dc7ef55 100644 --- a/src/shared/shl_log.c +++ b/src/shared/shl_log.c @@ -238,3 +238,30 @@ void log_llog(void *data, { log_submit(file, line, func, subs, sev, format, args); } + +int log_parse_arg(char *optarg) +{ + int log_max_sev; + if(!strcasecmp(optarg, "fatal")) { + log_max_sev = LOG_FATAL; + } else if(!strcasecmp(optarg, "alert")) { + log_max_sev = LOG_ALERT; + } else if(!strcasecmp(optarg, "critical")) { + log_max_sev = LOG_CRITICAL; + } else if(!strcasecmp(optarg, "error")) { + log_max_sev = LOG_ERROR; + } else if(!strcasecmp(optarg, "warning")) { + log_max_sev = LOG_WARNING; + } else if(!strcasecmp(optarg, "notice")) { + log_max_sev = LOG_NOTICE; + } else if(!strcasecmp(optarg, "info")) { + log_max_sev = LOG_INFO; + } else if(!strcasecmp(optarg, "debug")) { + log_max_sev = LOG_DEBUG; + } else if(!strcasecmp(optarg, "trace")) { + log_max_sev = LOG_TRACE; + } else { + log_max_sev = atoi(optarg); + } + return log_max_sev; +} diff --git a/src/shared/shl_log.h b/src/shared/shl_log.h index 5b49724..e645948 100644 --- a/src/shared/shl_log.h +++ b/src/shared/shl_log.h @@ -116,6 +116,8 @@ void log_llog(void *data, const char *format, va_list args); +int log_parse_arg(char *optarg); + static inline __attribute__((format(printf, 2, 3))) void log_dummyf(unsigned int sev, const char *format, ...) { diff --git a/src/wifi/wifid.c b/src/wifi/wifid.c index 37432b8..53622a8 100644 --- a/src/wifi/wifid.c +++ b/src/wifi/wifid.c @@ -502,7 +502,7 @@ static int parse_argv(int argc, char *argv[]) puts(PACKAGE_STRING); return 0; case ARG_LOG_LEVEL: - log_max_sev = atoi(optarg); + log_max_sev = log_parse_arg(optarg); break; case ARG_LOG_TIME: log_init_time(); @@ -512,7 +512,7 @@ static int parse_argv(int argc, char *argv[]) arg_wpa_bindir = optarg; break; case ARG_WPA_LOGLEVEL: - arg_wpa_loglevel = atoi(optarg); + arg_wpa_loglevel = log_parse_arg(optarg); break; case '?': return -EINVAL;