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.naydanov@syntacore.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8071
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
Evgeniy Naydanov 2024-01-10 19:23:53 +03:00 committed by Antonio Borneo
parent 50be4bd267
commit d0548940f2
2 changed files with 22 additions and 24 deletions

View File

@ -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]

View File

@ -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",