This is an automated email from Gerrit. Tarek BOCHKATI ([email protected]) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/6427
-- gerrit commit 451de8d69cbd6b7f49438da4c36a573fd63414c0 Author: Tarek BOCHKATI <[email protected]> Date: Wed Aug 11 01:14:21 2021 +0100 helper/log: add new log command 'log <level> <message>' This new command logs a message with the specified priority. The message will be displayed if it is allowed by the configured verbosity (debug_level). This command could be used within configuration scripts for logging propose. Change-Id: I3cf83d9aa8de2acbb5dfc9a234bc3872a014037d Signed-off-by: Tarek BOCHKATI <[email protected]> diff --git a/doc/openocd.texi b/doc/openocd.texi index 3aee034..1009a55 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -8218,6 +8218,14 @@ file (which is normally the server's standard output). @xref{Running}. @end deffn +@deffn {Command} {log} level message +Logs a message at "level" priority. +the accepted levels are: debug, info, warning, error and user. +@example +log error "cannot initialize the external memory" +@end example +@end deffn + @deffn {Command} {echo} [-n] message Logs a message at "user" priority. Option "-n" suppresses trailing newline. diff --git a/src/helper/log.c b/src/helper/log.c index caa0a66..f59975d 100644 --- a/src/helper/log.c +++ b/src/helper/log.c @@ -227,6 +227,29 @@ COMMAND_HANDLER(handle_debug_level_command) return ERROR_OK; } +COMMAND_HANDLER(handle_log_command) +{ + if (CMD_ARGC != 2) + return ERROR_COMMAND_SYNTAX_ERROR; + + if (strcmp("debug", CMD_ARGV[0]) == 0) { + LOG_DEBUG("%s", CMD_ARGV[1]); + } else if (strcmp("info", CMD_ARGV[0]) == 0) { + LOG_INFO("%s", CMD_ARGV[1]); + } else if (strcmp("warning", CMD_ARGV[0]) == 0) { + LOG_WARNING("%s", CMD_ARGV[1]); + } else if (strcmp("error", CMD_ARGV[0]) == 0) { + LOG_ERROR("%s", CMD_ARGV[1]); + } else if (strcmp("user", CMD_ARGV[0]) == 0) { + LOG_USER("%s", CMD_ARGV[1]); + } else { + LOG_ERROR("unknown log level '%s'", CMD_ARGV[1]); + return ERROR_COMMAND_ARGUMENT_INVALID; + } + + return ERROR_OK; +} + COMMAND_HANDLER(handle_log_output_command) { if (CMD_ARGC == 0 || (CMD_ARGC == 1 && strcmp(CMD_ARGV[0], "default") == 0)) { @@ -274,6 +297,13 @@ static const struct command_registration log_command_handlers[] = { "4 adds extra verbose debugging.", .usage = "number", }, + { + .name = "log", + .handler = handle_log_command, + .mode = COMMAND_ANY, + .help = "print a log message wit a specific level", + .usage = "level message", + }, COMMAND_REGISTRATION_DONE }; --
