From: openocd-gerrit <ope...@us...> - 2024-02-11 23:07:43
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via d0548940f289fbb6c3ce61106799aa56ec20f188 (commit) from 50be4bd2672916f9262df31108d4611c2b0fbf44 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit d0548940f289fbb6c3ce61106799aa56ec20f188 Author: Evgeniy Naydanov <evg...@sy...> Date: Wed Jan 10 19:23:53 2024 +0300 helper/log: report the file in `log_output` command Prior to the change when calling `log_output` without any arguments it was unclear where the log was redirected. Change-Id: Iaa3ecea8166f9c7ec8aad7adf5bd412799f719a1 Signed-off-by: Evgeniy Naydanov <evg...@sy...> Reviewed-on: https://review.openocd.org/c/openocd/+/8071 Tested-by: jenkins Reviewed-by: Antonio Borneo <bor...@gm...> diff --git a/doc/openocd.texi b/doc/openocd.texi index a4e7c6aaa..38c897045 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -9035,9 +9035,10 @@ echo "Downloading kernel -- please wait" @end example @end deffn -@deffn {Command} {log_output} [filename | "default"] -Redirect logging to @var{filename} or set it back to default output; -the default log output channel is stderr. +@deffn {Command} {log_output} [filename | 'default'] +Redirect logging to @var{filename}. If used without an argument or +@var{filename} is set to 'default' log output channel is set to +stderr. @end deffn @deffn {Command} {add_script_search_dir} [directory] diff --git a/src/helper/log.c b/src/helper/log.c index a4fc53d4b..471069ade 100644 --- a/src/helper/log.c +++ b/src/helper/log.c @@ -214,31 +214,28 @@ COMMAND_HANDLER(handle_debug_level_command) COMMAND_HANDLER(handle_log_output_command) { - if (CMD_ARGC == 0 || (CMD_ARGC == 1 && strcmp(CMD_ARGV[0], "default") == 0)) { - if (log_output != stderr && log_output) { - /* Close previous log file, if it was open and wasn't stderr. */ - fclose(log_output); - } - log_output = stderr; - LOG_DEBUG("set log_output to default"); - return ERROR_OK; - } - if (CMD_ARGC == 1) { - FILE *file = fopen(CMD_ARGV[0], "w"); + if (CMD_ARGC > 1) + return ERROR_COMMAND_SYNTAX_ERROR; + + FILE *file; + if (CMD_ARGC == 1 && strcmp(CMD_ARGV[0], "default") != 0) { + file = fopen(CMD_ARGV[0], "w"); if (!file) { - LOG_ERROR("failed to open output log '%s'", CMD_ARGV[0]); + command_print(CMD, "failed to open output log \"%s\"", CMD_ARGV[0]); return ERROR_FAIL; } - if (log_output != stderr && log_output) { - /* Close previous log file, if it was open and wasn't stderr. */ - fclose(log_output); - } - log_output = file; - LOG_DEBUG("set log_output to \"%s\"", CMD_ARGV[0]); - return ERROR_OK; + command_print(CMD, "set log_output to \"%s\"", CMD_ARGV[0]); + } else { + file = stderr; + command_print(CMD, "set log_output to default"); } - return ERROR_COMMAND_SYNTAX_ERROR; + if (log_output != stderr && log_output) { + /* Close previous log file, if it was open and wasn't stderr. */ + fclose(log_output); + } + log_output = file; + return ERROR_OK; } static const struct command_registration log_command_handlers[] = { @@ -247,7 +244,7 @@ static const struct command_registration log_command_handlers[] = { .handler = handle_log_output_command, .mode = COMMAND_ANY, .help = "redirect logging to a file (default: stderr)", - .usage = "[file_name | \"default\"]", + .usage = "[file_name | 'default']", }, { .name = "debug_level", ----------------------------------------------------------------------- Summary of changes: doc/openocd.texi | 7 ++++--- src/helper/log.c | 39 ++++++++++++++++++--------------------- 2 files changed, 22 insertions(+), 24 deletions(-) hooks/post-receive -- Main OpenOCD repository |