mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH] commands: dmesg: add -p option for setting maximum log level
Date: Mon,  9 Jun 2025 08:34:59 +0200	[thread overview]
Message-ID: <20250609063459.3167639-1-a.fatoum@barebox.org> (raw)

The existing -l option requires the user to specify all log levels they
are interested in, e.g. dmesg -l warn,err,crit,alert,emerg, which is
cumbersome.

Add a new -p option that automatically includes more severe log levels,
so the above can be realized by just dmesg -p warn

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 commands/dmesg.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/commands/dmesg.c b/commands/dmesg.c
index 8a60f075076e..a93ad5b359fb 100644
--- a/commands/dmesg.c
+++ b/commands/dmesg.c
@@ -81,7 +81,7 @@ static int do_dmesg(int argc, char *argv[])
 	unsigned flags = 0, levels = 0;
 	char *set = NULL;
 
-	while ((opt = getopt(argc, argv, "ctderl:n:")) > 0) {
+	while ((opt = getopt(argc, argv, "ctderl:p:n:")) > 0) {
 		switch (opt) {
 		case 'c':
 			delete_buf = 1;
@@ -96,9 +96,16 @@ static int do_dmesg(int argc, char *argv[])
 			emit = 1;
 			break;
 		case 'l':
+		case 'p':
 			levels = dmesg_get_levels(optarg);
 			if (!levels)
 				return COMMAND_ERROR;
+			if (opt == 'p') {
+				unsigned maxbit = fls(levels) - 1;
+				if (levels & ~BIT(maxbit))
+					return COMMAND_ERROR_USAGE;
+				levels = GENMASK(maxbit, 0);
+			}
 			break;
 		case 'r':
 			flags |= BAREBOX_LOG_PRINT_RAW | BAREBOX_LOG_PRINT_TIME;
@@ -170,6 +177,7 @@ 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")
 BAREBOX_CMD_HELP_OPT ("-l <loglevel>", "Restrict output to the given (comma-separated) list of levels")
+BAREBOX_CMD_HELP_OPT ("-p <loglevel>", "Restrict output to specified log level at most")
 BAREBOX_CMD_HELP_OPT ("-n <loglevel>", "Set level at which printing of messages is done to the console")
 BAREBOX_CMD_HELP_OPT ("-r",		"Print timestamp and log-level prefixes.")
 BAREBOX_CMD_HELP_OPT ("-t",		"Show timestamp informations")
@@ -178,7 +186,7 @@ BAREBOX_CMD_HELP_END
 BAREBOX_CMD_START(dmesg)
 	.cmd	= do_dmesg,
 	BAREBOX_CMD_DESC("Print or control log messages")
-	BAREBOX_CMD_OPTS("[-cdert]")
+	BAREBOX_CMD_OPTS("[-cdelprt]")
 	BAREBOX_CMD_GROUP(CMD_GRP_INFO)
 	BAREBOX_CMD_HELP(cmd_dmesg_help)
 BAREBOX_CMD_END
-- 
2.39.5




             reply	other threads:[~2025-06-09  6:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-09  6:34 Ahmad Fatoum [this message]
2025-06-10  6:23 ` Sascha Hauer

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=20250609063459.3167639-1-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --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