[PATCH] dmesg: handle colorization of emerg/notice/info/debug levels

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,
please find attached a very simple patch which allows consistent customization
of the coloring schemes  of the emerg, notice, info and debug levels in dmesg.
(currently only alert, crit, err and warn coloring schemes could be customized).

output changes (when coloring enabled):
	emerg level takes a default reverse+red, as alert and crit.
	debug level takes dark gray (seems reasonable)

As my color choices might not suit the masses (or even offend them!),
notice and info levels are unaffected and keep a default reset vt100 sequence.
Afterall, they could then be customized via /etc/terminal-colors.d/dmesg.scheme

== LEGAL STUFF ==
Due to the triviality of the patch, I HEREBY EXPLICITELY DISMISS any right, copyrights, whatsoever,
applying to this patch, with or without changes, and grant the right to the maintainers, authors,
or whoever, to have it applied, even on his/her own name, without even mentioning me,
hoping this will make things faster and paperless, and useful to the community.
(If this is not sufficient or explicit enough, please tell, but, honestly...)

Regards, Thanks & Happy new year, if not too late.

--
Steve
diff -ru sys-utils.orig/dmesg.1.adoc sys-utils/dmesg.1.adoc
--- sys-utils.orig/dmesg.1.adoc	2022-02-02 21:23:39.220901256 +0100
+++ sys-utils/dmesg.1.adoc	2022-02-02 21:28:55.355191631 +0100
@@ -159,6 +159,9 @@
 *timebreak*::
 The message timestamp in short ctime format in *--reltime* or *--human* output.
 
+*emerg*::
+The text of the message with the emerg log priority.
+
 *alert*::
 The text of the message with the alert log priority.
 
@@ -171,6 +174,15 @@
 *warn*::
 The text of the message with the warning log priority.
 
+*notice*::
+The text of the message with the notice log priority.
+
+*info*::
+The text of the message with the info log priority.
+
+*debug*::
+The text of the message with the debug log priority.
+
 *segfault*::
 The text of the message that inform about segmentation fault.
 
diff -ru sys-utils.orig/dmesg.c sys-utils/dmesg.c
--- sys-utils.orig/dmesg.c	2022-02-02 21:23:39.224901283 +0100
+++ sys-utils/dmesg.c	2022-02-02 22:02:56.918640093 +0100
@@ -71,10 +71,14 @@
 	DMESG_COLOR_SUBSYS,
 	DMESG_COLOR_TIME,
 	DMESG_COLOR_TIMEBREAK,
+	DMESG_COLOR_EMERG,
 	DMESG_COLOR_ALERT,
 	DMESG_COLOR_CRIT,
 	DMESG_COLOR_ERR,
 	DMESG_COLOR_WARN,
+	DMESG_COLOR_NOTICE,
+	DMESG_COLOR_INFO,
+	DMESG_COLOR_DEBUG,
 	DMESG_COLOR_SEGFAULT
 };
 
@@ -83,10 +87,14 @@
 	[DMESG_COLOR_SUBSYS]    = { "subsys",	UL_COLOR_BROWN },
 	[DMESG_COLOR_TIME]	= { "time",     UL_COLOR_GREEN },
 	[DMESG_COLOR_TIMEBREAK]	= { "timebreak",UL_COLOR_GREEN UL_COLOR_BOLD },
+	[DMESG_COLOR_EMERG]	= { "emerg",    UL_COLOR_REVERSE UL_COLOR_RED },
 	[DMESG_COLOR_ALERT]	= { "alert",    UL_COLOR_REVERSE UL_COLOR_RED },
 	[DMESG_COLOR_CRIT]	= { "crit",     UL_COLOR_BOLD UL_COLOR_RED },
 	[DMESG_COLOR_ERR]       = { "err",      UL_COLOR_RED },
 	[DMESG_COLOR_WARN]	= { "warn",     UL_COLOR_BOLD },
+	[DMESG_COLOR_NOTICE]	= { "notice",     UL_COLOR_RESET },
+	[DMESG_COLOR_INFO]	= { "info",     UL_COLOR_RESET },
+	[DMESG_COLOR_DEBUG]	= { "debug",     UL_COLOR_DARK_GRAY },
 	[DMESG_COLOR_SEGFAULT]	= { "segfault", UL_COLOR_HALFBRIGHT UL_COLOR_RED }
 };
 
@@ -235,6 +243,9 @@
 	int id = -1;
 
 	switch (log_level) {
+	case LOG_EMERG:
+		id = DMESG_COLOR_EMERG;
+		break;
 	case LOG_ALERT:
 		id = DMESG_COLOR_ALERT;
 		break;
@@ -247,6 +258,15 @@
 	case LOG_WARNING:
 		id = DMESG_COLOR_WARN;
 		break;
+	case LOG_NOTICE:
+		id = DMESG_COLOR_NOTICE;
+		break;
+	case LOG_INFO:
+		id = DMESG_COLOR_INFO;
+		break;
+	case LOG_DEBUG:
+		id = DMESG_COLOR_DEBUG;
+		break;
 	default:
 		break;
 	}

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux