Skip to content

Commit

Permalink
sys/log: Add log-fill command
Browse files Browse the repository at this point in the history
This adds log-fill command to the log cli.
It allows to fill specific log with auto generated logs.
usage:

log-fill <count> [<log name>]

i.e.:

log-fill 1000 reboot_log

Command is added when syscfg value LOG_CLI_FILL_CMD is set

Signed-off-by: Jerzy Kasenberg <jerzy.kasenberg@codecoup.pl>
  • Loading branch information
kasjer committed Aug 5, 2024
1 parent 9a0fedf commit bb6c3b2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sys/log/full/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@ pkg.req_apis.LOG_STATS:

pkg.init:
log_init: 'MYNEWT_VAL(LOG_SYSINIT_STAGE_MAIN)'

pkg.init.LOG_CLI_FILL_CMD:
shell_log_fill_register: $after:shell_init
41 changes: 41 additions & 0 deletions sys/log/full/src/log_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,45 @@ shell_log_storage_cmd(int argc, char **argv)
}
#endif

static int
log_fill_command(int argc, char **argv)
{
const char *log_name;
struct log *log;
int num = 1;

if (argc > 2) {
log_name = argv[2];
log = log_find(log_name);
} else {
log = log_list_get_next(NULL);
}
if (log == NULL) {
console_printf("No log to fill\n");
return -1;
}
if (argc > 1) {
num = atoi(argv[1]);
if (num <= 0 || num > 10000) {
num = 1;
}
}

for (int i = 0; i < num; ++i) {
log_printf(log, MODLOG_MODULE_DFLT, LOG_LEVEL_INFO, "Log os_time %d", (int)os_time_get());
}

return 0;
}

static struct shell_cmd log_fill_cmd = {
.sc_cmd = "log-fill",
.sc_cmd_func = log_fill_command
};

void
shell_log_fill_register(void)
{
shell_cmd_register(&log_fill_cmd);
}
#endif
4 changes: 4 additions & 0 deletions sys/log/full/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ syscfg.defs:
restrictions:
- SHELL_TASK

LOG_CLI_FILL_CMD:
description: 'Add "log-fill" command for filling up log'
value: 0

LOG_SHELL_SHOW_INDEX:
description: '"log" command shows log index when dumping entries'
value: 0
Expand Down

0 comments on commit bb6c3b2

Please sign in to comment.