* [PATCH] dmesg: add support for dumping log into file
@ 2025-02-18 12:43 Ahmad Fatoum
0 siblings, 0 replies; only message in thread
From: Ahmad Fatoum @ 2025-02-18 12:43 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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@pengutronix.de>
---
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-02-18 12:43 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-18 12:43 [PATCH] dmesg: add support for dumping log into file Ahmad Fatoum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox