From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] dmesg: add support for dumping log into file
Date: Tue, 18 Feb 2025 13:43:00 +0100 [thread overview]
Message-ID: <20250218124300.3862498-1-a.fatoum@pengutronix.de> (raw)
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
reply other threads:[~2025-02-18 12:43 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250218124300.3862498-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox