From 24224efa33b277c2905c03b8382a854045505782 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 28 May 2009 07:52:03 +0000 Subject: [PATCH] allow people to retrieve current log level by running `debug` git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1635 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- urjtag/ChangeLog | 2 + urjtag/src/cmd/cmd_debug.c | 92 +++++++++++++++++++++++++++----------- 2 files changed, 67 insertions(+), 27 deletions(-) diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index 17b32022..aca0afb2 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -6,6 +6,8 @@ * src/tap/detect.c: if the part could not be found because the data file could not be opened, then log an obvious error message + * src/cmd/cmd_debug.c: display current log level if no arguments specified + 2009-05-24 Rutger Hofman * src/bus/avr32.c: fix uninitialized warning (Florian Fainelli) diff --git a/urjtag/src/cmd/cmd_debug.c b/urjtag/src/cmd/cmd_debug.c index b0b35f57..a0734203 100644 --- a/urjtag/src/cmd/cmd_debug.c +++ b/urjtag/src/cmd/cmd_debug.c @@ -34,42 +34,80 @@ #include "cmd.h" +static urj_log_level_t +string_to_log_level (const char *strlevel) +{ + if (0) + ; + else if (strcasecmp(strlevel, "all") == 0) + return URJ_LOG_LEVEL_ALL; + else if (strcasecmp(strlevel, "comm") == 0) + return URJ_LOG_LEVEL_COMM; + else if (strcasecmp(strlevel, "debug") == 0) + return URJ_LOG_LEVEL_DEBUG; + else if (strcasecmp(strlevel, "detail") == 0) + return URJ_LOG_LEVEL_DETAIL; + else if (strcasecmp(strlevel, "normal") == 0) + return URJ_LOG_LEVEL_NORMAL; + else if (strcasecmp(strlevel, "warning") == 0) + return URJ_LOG_LEVEL_WARNING; + else if (strcasecmp(strlevel, "error") == 0) + return URJ_LOG_LEVEL_ERROR; + else if (strcasecmp(strlevel, "silent") == 0) + return URJ_LOG_LEVEL_SILENT; + else + return -1; +} + +static const char * +log_level_to_string (urj_log_level_t level) +{ + switch (level) { + case URJ_LOG_LEVEL_ALL: return "all"; + case URJ_LOG_LEVEL_COMM: return "comm"; + case URJ_LOG_LEVEL_DEBUG: return "debug"; + case URJ_LOG_LEVEL_DETAIL: return "detail"; + case URJ_LOG_LEVEL_NORMAL: return "normal"; + case URJ_LOG_LEVEL_WARNING: return "warning"; + case URJ_LOG_LEVEL_ERROR: return "error"; + case URJ_LOG_LEVEL_SILENT: return "silent"; + case -1: /* sanity for string_to_log_level() return */ + default: return "unknown"; + } +} + static int cmd_debug_run (urj_chain_t *chain, char *params[]) { - if (urj_cmd_params (params) != 2) + switch (urj_cmd_params (params)) { + + /* display current log level */ + case 1: + urj_log (URJ_LOG_LEVEL_NORMAL, _("Current log level is '%s'\n"), + log_level_to_string (urj_log_state.level)); + return URJ_STATUS_OK; + + /* set log level */ + case 2: { + urj_log_level_t new_level = string_to_log_level (params[1]); + if (new_level == -1) + { + urj_error_set (URJ_ERROR_SYNTAX, "unknown log level '%s'", params[1]); + return URJ_STATUS_FAIL; + } + urj_log_state.level = new_level; + + return URJ_STATUS_OK; + } + + /* fail! */ + default: urj_error_set (URJ_ERROR_SYNTAX, "%s: #parameters should be %d, not %d", params[0], 2, urj_cmd_params (params)); return URJ_STATUS_FAIL; } - - if (0) - ; - else if (strcasecmp(params[1], "all") == 0) - urj_log_state.level = URJ_LOG_LEVEL_ALL; - else if (strcasecmp(params[1], "comm") == 0) - urj_log_state.level = URJ_LOG_LEVEL_COMM; - else if (strcasecmp(params[1], "debug") == 0) - urj_log_state.level = URJ_LOG_LEVEL_DEBUG; - else if (strcasecmp(params[1], "detail") == 0) - urj_log_state.level = URJ_LOG_LEVEL_DETAIL; - else if (strcasecmp(params[1], "normal") == 0) - urj_log_state.level = URJ_LOG_LEVEL_NORMAL; - else if (strcasecmp(params[1], "warning") == 0) - urj_log_state.level = URJ_LOG_LEVEL_WARNING; - else if (strcasecmp(params[1], "error") == 0) - urj_log_state.level = URJ_LOG_LEVEL_ERROR; - else if (strcasecmp(params[1], "silent") == 0) - urj_log_state.level = URJ_LOG_LEVEL_SILENT; - else - { - urj_error_set (URJ_ERROR_SYNTAX, "unknown log level '%s'", params[1]); - return URJ_STATUS_FAIL; - } - - return URJ_STATUS_OK; } static void