aboutsummaryrefslogtreecommitdiff
path: root/src/helper/log.c
diff options
context:
space:
mode:
authorEvgeniy Naydanov <evgeniy.naydanov@syntacore.com>2024-01-10 19:23:53 +0300
committerAntonio Borneo <borneo.antonio@gmail.com>2024-02-11 23:07:09 +0000
commitd0548940f289fbb6c3ce61106799aa56ec20f188 (patch)
tree069af7d4a3b735106a2746556a4fbc032fea1960 /src/helper/log.c
parent50be4bd2672916f9262df31108d4611c2b0fbf44 (diff)
downloadriscv-openocd-d0548940f289fbb6c3ce61106799aa56ec20f188.zip
riscv-openocd-d0548940f289fbb6c3ce61106799aa56ec20f188.tar.gz
riscv-openocd-d0548940f289fbb6c3ce61106799aa56ec20f188.tar.bz2
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>
Diffstat (limited to 'src/helper/log.c')
-rw-r--r--src/helper/log.c39
1 files changed, 18 insertions, 21 deletions
diff --git a/src/helper/log.c b/src/helper/log.c
index a4fc53d..471069a 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",