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.
@@ -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,6 +158,13 @@ shell_log_dump_cmd(int argc, char **argv)
continue;
}
+ if (clear_log) {
+ console_printf("Clearing log %s\n", log->l_name);
+ rc = log_flush(log);
+ if (rc != 0) {
+ goto err;
+ }
+ } else {
console_printf("Dumping log %s\n", log->l_name);
log_offset.lo_arg = NULL;
@@ -166,6 +182,7 @@ shell_log_dump_cmd(int argc, char **argv)
goto err;
}
}
+ }
return (0);
err:
