This is an automated email from Gerrit. "Evgeniy Naydanov <evgeniy.nayda...@syntacore.com>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8071
-- gerrit commit 42c299afadcd0bbe3dbf4af451e5759fa4cb0fc8 Author: Evgeniy Naydanov <evgeniy.nayda...@syntacore.com> 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 <evgeniy.nayda...@syntacore.com> diff --git a/doc/openocd.texi b/doc/openocd.texi index 53730eafaf..36a0de1064 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -9026,9 +9026,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 a4fc53d4b5..015e6a0c76 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]); 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", --