This is an automated email from the ASF dual-hosted git repository. wes3 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push: new a7ea0b0aa sys/log: Add clearing log to log command a7ea0b0aa is described below commit a7ea0b0aab1a07a36d0f863587664970d43ae254 Author: Will San Filippo <william.sanfili...@juul.com> AuthorDate: Thu Apr 28 14:20:18 2022 -0700 sys/log: Add clearing log to log command This commit adds the ability to clear a log, a group of logs or all logs using the 'log' shell command. The option -c was added for this purpose. The syntax is similar to the log dump syntax. --- sys/log/full/src/log_shell.c | 45 ++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/sys/log/full/src/log_shell.c b/sys/log/full/src/log_shell.c index 716ae86c2..48db8a822 100644 --- a/sys/log/full/src/log_shell.c +++ b/sys/log/full/src/log_shell.c @@ -109,16 +109,25 @@ shell_log_dump_cmd(int argc, char **argv) uint32_t log_limit = 0; bool stream; bool partial_match = false; + bool clear_log; int i; int rc; + clear_log = false; for (i = 1; i < argc; ++i) { if (0 == strcmp(argv[i], "-l")) { list_only = true; break; } - if (isdigit((unsigned char)argv[i][0])) { + + /* the -c option is to clear a log (or logs). */ + if (!strcmp(argv[i], "-c")) { + clear_log = true; + } else if (isdigit((unsigned char)argv[i][0])) { log_limit = parse_ll_bounds(argv[i], 1, 1000000, &rc); + if (clear_log) { + goto err; + } } else { log_name = argv[i]; if ('*' == log_name[strlen(log_name) - 1]) { @@ -149,21 +158,29 @@ shell_log_dump_cmd(int argc, char **argv) continue; } - console_printf("Dumping log %s\n", log->l_name); - - log_offset.lo_arg = NULL; - log_offset.lo_ts = 0; - log_last_index = log_get_last_index(log); - if (log_limit == 0 || log_last_index < log_limit) { - log_offset.lo_index = 0; + if (clear_log) { + console_printf("Clearing log %s\n", log->l_name); + rc = log_flush(log); + if (rc != 0) { + goto err; + } } else { - log_offset.lo_index = log_last_index - log_limit; - } - log_offset.lo_data_len = 0; + console_printf("Dumping log %s\n", log->l_name); + + log_offset.lo_arg = NULL; + log_offset.lo_ts = 0; + log_last_index = log_get_last_index(log); + if (log_limit == 0 || log_last_index < log_limit) { + log_offset.lo_index = 0; + } else { + log_offset.lo_index = log_last_index - log_limit; + } + log_offset.lo_data_len = 0; - rc = log_walk_body(log, shell_log_dump_entry, &log_offset); - if (rc != 0) { - goto err; + rc = log_walk_body(log, shell_log_dump_entry, &log_offset); + if (rc != 0) { + goto err; + } } }