We already have a log_writefile() helper for dumping the log into a file. Make it easily accessible via the shell by having a new dmesg -o option call it. There is nothing keeping us from extending the function to support flags and levels like log_print does, but this can follow later if needed. Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx> --- commands/dmesg.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/commands/dmesg.c b/commands/dmesg.c index 8a60f075076e..7982188cda6d 100644 --- a/commands/dmesg.c +++ b/commands/dmesg.c @@ -76,13 +76,17 @@ static unsigned dmesg_get_levels(const char *__args) static int do_dmesg(int argc, char *argv[]) { + const char *outputfile = NULL; int opt, ret, i; int delete_buf = 0, emit = 0; unsigned flags = 0, levels = 0; char *set = NULL; - while ((opt = getopt(argc, argv, "ctderl:n:")) > 0) { + while ((opt = getopt(argc, argv, "o:ctderl:n:")) > 0) { switch (opt) { + case 'o': + outputfile = optarg; + break; case 'c': delete_buf = 1; break; @@ -111,6 +115,12 @@ static int do_dmesg(int argc, char *argv[]) } } + if (outputfile) { + if (flags || levels) + return COMMAND_ERROR_USAGE; + return log_writefile(outputfile); + } + if (set) { int level = str_to_loglevel(set); @@ -166,6 +176,7 @@ BAREBOX_CMD_HELP_TEXT("Known debug loglevels are: emerg, alert, crit, err, warn, BAREBOX_CMD_HELP_TEXT("vdebug") BAREBOX_CMD_HELP_TEXT("") BAREBOX_CMD_HELP_TEXT("Options:") +BAREBOX_CMD_HELP_OPT ("-o <file>", "Output all log to given file (conflicts with -tdlr)") BAREBOX_CMD_HELP_OPT ("-c", "Delete messages after printing them") BAREBOX_CMD_HELP_OPT ("-d", "Show a time delta to the last message") BAREBOX_CMD_HELP_OPT ("-e <msg>", "Emit a log message") -- 2.39.5