The log level that is not initialized is set to invalid. the default log level is set to none. wd_parse_log_level should only execute one time.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- wd.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-)
diff --git a/wd.c b/wd.c index a6acf8b..c2559a4 100644 --- a/wd.c +++ b/wd.c @@ -23,13 +23,14 @@ #define SYS_CLASS_DIR "/sys/class/uacce"
enum UADK_LOG_LEVEL { - LOG_NONE = 0, + WD_LOG_NONE = 0, WD_LOG_ERROR, WD_LOG_INFO, WD_LOG_DEBUG, + WD_LOG_INVALID, };
-static int uadk_log_level = -1; +static int uadk_log_level = WD_LOG_INVALID;
struct wd_ctx_h { int fd; @@ -52,6 +53,9 @@ static void wd_parse_log_level(void) char *file_contents; FILE *in_file;
+ if (uadk_log_level == WD_LOG_INVALID) + uadk_log_level = WD_LOG_NONE; + in_file = fopen(syslog_file, "r"); if (!in_file) { WD_ERR("failed to open the rsyslog.conf file.\n"); @@ -869,18 +873,36 @@ void wd_get_version(void)
bool wd_need_debug(void) { - if (uadk_log_level < 0) + switch (uadk_log_level) { + case WD_LOG_NONE: + case WD_LOG_ERROR: + case WD_LOG_INFO: + return false; + case WD_LOG_DEBUG: + return true; + case WD_LOG_INVALID: wd_parse_log_level(); - - return uadk_log_level >= WD_LOG_DEBUG; + return uadk_log_level >= WD_LOG_DEBUG; + default: + return false; + } }
bool wd_need_info(void) { - if (uadk_log_level < 0) + switch (uadk_log_level) { + case WD_LOG_NONE: + case WD_LOG_ERROR: + return false; + case WD_LOG_INFO: + case WD_LOG_DEBUG: + return true; + case WD_LOG_INVALID: wd_parse_log_level(); - - return uadk_log_level >= WD_LOG_INFO; + return uadk_log_level >= WD_LOG_INFO; + default: + return false; + } }
char *wd_ctx_get_dev_name(handle_t h_ctx)