mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] commands: dmesg: add -p option for setting maximum log level
@ 2025-06-09  6:34 Ahmad Fatoum
  2025-06-10  6:23 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2025-06-09  6:34 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] commands: dmesg: add -p option for setting maximum log level
  2025-06-09  6:34 [PATCH] commands: dmesg: add -p option for setting maximum log level Ahmad Fatoum
@ 2025-06-10  6:23 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2025-06-10  6:23 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Mon, 09 Jun 2025 08:34:59 +0200, Ahmad Fatoum wrote:
> 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
> 
> [...]

Applied, thanks!

[1/1] commands: dmesg: add -p option for setting maximum log level
      https://git.pengutronix.de/cgit/barebox/commit/?id=70506d022e3b (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-06-10  6:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-09  6:34 [PATCH] commands: dmesg: add -p option for setting maximum log level Ahmad Fatoum
2025-06-10  6:23 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox