This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 97a90d5573e3939d97dfea5b3f5f9d8e10164972
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Wed Jul 31 19:38:02 2024 +0200

    sys/log: Add log-fill command
    
    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 <[email protected]>
---
 sys/log/full/pkg.yml         |  3 +++
 sys/log/full/src/log_shell.c | 41 +++++++++++++++++++++++++++++++++++++++++
 sys/log/full/syscfg.yml      |  4 ++++
 3 files changed, 48 insertions(+)

diff --git a/sys/log/full/pkg.yml b/sys/log/full/pkg.yml
index c8b8b0abf..fe6f8c8b2 100644
--- a/sys/log/full/pkg.yml
+++ b/sys/log/full/pkg.yml
@@ -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
diff --git a/sys/log/full/src/log_shell.c b/sys/log/full/src/log_shell.c
index 0f0036e16..a1d446c7e 100644
--- a/sys/log/full/src/log_shell.c
+++ b/sys/log/full/src/log_shell.c
@@ -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
diff --git a/sys/log/full/syscfg.yml b/sys/log/full/syscfg.yml
index 91709976f..d48ae9703 100644
--- a/sys/log/full/syscfg.yml
+++ b/sys/log/full/syscfg.yml
@@ -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

Reply via email to