"The following patch makes it possible to give kernel messages a selectable color which helps to distinguish it from other noise, such as boot messages," explained Jan Engelhardt, along with a 43 line patch to the char driver. As justification for the patch he offered, "NetBSD has it, OpenBSD has it, FreeBSD to some extent, so I think Linux should too." He also noted that an earlier version of the small patch had been previously posted back in April.
Ingo Molnar responded favorably, "looks really good to me!" He went on to suggest, "feature request: would be interesting to have a color table (defined in the .config) dependent on message loglevel. That way KERN_CRIT messages could be red, KERN_INFO ones white, etc."
From: Jan Engelhardt <jengelh@...>
Subject: [PATCH] Cute feature: colored printk output
Date: Oct 5, 3:13 pm 2007
Colored kernel message output
Let's work more on Linux's cuteness! [http://lkml.org/lkml/2007/10/4/431]
The following patch makes it possible to give kernel messages a
selectable color which helps to distinguish it from other noise,
such as boot messages. NetBSD has it, OpenBSD has it, FreeBSD to some
extent, so I think Linux should too.
Inspired by cko (http://freshmeat.net/p/cko/), but independently
written, later contributed forth and back.
Already posted at: http://lkml.org/lkml/2007/4/1/162
Signed-off-by: Jan Engelhardt <jengelh@gmx.de>
---
drivers/char/Kconfig | 29 +++++++++++++++++++++++++++++
drivers/char/vt.c | 14 ++++++++++++++
2 files changed, 43 insertions(+)
Index: linux-2.6.23/drivers/char/Kconfig
===================================================================
--- linux-2.6.23.orig/drivers/char/Kconfig
+++ linux-2.6.23/drivers/char/Kconfig
@@ -58,6 +58,35 @@ config VT_CONSOLE
If unsure, say Y.
+config VT_PRINTK_COLOR
+ hex "Colored kernel message output"
+ range 0x00 0xFF
+ depends on VT_CONSOLE
+ default 0x17
+ ---help---
+ This option will give you ability to change the color of
+ kernel messages printed to the console.
+
+ The value you need to enter here is the ASCII color value
+ composed (OR'ed) by one foreground color, one background
+ color and any number of attributes as follows:
+
+ Foreground:
+ 0x00=black, 0x01=blue, 0x02=green, 0x03=green,
+ 0x04=red, 0x05=magenta, 0x06=brown, 0x07=gray
+
+ Background:
+ 0x00=black, 0x10=blue, 0x20=green, 0x30=green,
+ 0x40=red, 0x50=magenta, 0x60=brown, 0x70=gray
+
+ Attributes:
+ 0x08=highlight foreground
+
+ Thus, 0x17 will yield gray-on-blue like in OpenBSD and
+ 0x02 green-on-black like in NetBSD.
+ Using "highlight foreground" is said not work when you use
+ VGA Console (Framebuffer not affected) with a 512-glyph font.
+
config HW_CONSOLE
bool
depends on VT && !S390 && !UML
Index: linux-2.6.23/drivers/char/vt.c
===================================================================
--- linux-2.6.23.orig/drivers/char/vt.c
+++ linux-2.6.23/drivers/char/vt.c
@@ -73,6 +73,7 @@
*/
#include <linux/module.h>
+#include <linux/moduleparam.h>
#include <linux/types.h>
#include <linux/sched.h>
#include <linux/tty.h>
@@ -2348,6 +2349,9 @@ struct tty_driver *console_driver;
#ifdef CONFIG_VT_CONSOLE
+static unsigned int printk_color = CONFIG_VT_PRINTK_COLOR;
+module_param(printk_color, uint, S_IRUGO | S_IWUSR);
+
/*
* Console on virtual terminal
*
@@ -2388,12 +2392,16 @@ static void vt_console_print(struct cons
hide_cursor(vc);
start = (ushort *)vc->vc_pos;
+ vc->vc_color = printk_color;
+ update_attr(vc);
/* Contrived structure to try to emulate original need_wrap behaviour
* Problems caused when we have need_wrap set on '\n' character */
while (count--) {
c = *b++;
if (c == 10 || c == 13 || c == 8 || vc->vc_need_wrap) {
+ vc->vc_color = vc->vc_def_color;
+ update_attr(vc);
if (cnt > 0) {
if (CON_IS_VISIBLE(vc))
vc->vc_sw->con_putcs(vc, start, cnt, vc->vc_y, vc->vc_x);
@@ -2406,6 +2414,8 @@ static void vt_console_print(struct cons
bs(vc);
start = (ushort *)vc->vc_pos;
myx = vc->vc_x;
+ vc->vc_color = printk_color;
+ update_attr(vc);
continue;
}
if (c != 13)
@@ -2413,6 +2423,8 @@ static void vt_console_print(struct cons
cr(vc);
start = (ushort *)vc->vc_pos;
myx = vc->vc_x;
+ vc->vc_color = printk_color;
+ update_attr(vc);
if (c == 10 || c == 13)
continue;
}
@@ -2434,6 +2446,8 @@ static void vt_console_print(struct cons
vc->vc_need_wrap = 1;
}
}
+ vc->vc_color = vc->vc_def_color;
+ update_attr(vc);
set_cursor(vc);
quit:
-
From: Ingo Molnar <mingo@...>
Subject: Re: [PATCH] Cute feature: colored printk output
Date: Oct 6, 7:08 am 2007
* Jan Engelhardt <jengelh@computergmbh.de> wrote:
> Colored kernel message output
>
> Let's work more on Linux's cuteness!
> [http://lkml.org/lkml/2007/10/4/431] The following patch makes it
> possible to give kernel messages a selectable color which helps to
> distinguish it from other noise, such as boot messages. NetBSD has it,
> OpenBSD has it, FreeBSD to some extent, so I think Linux should too.
>
> Inspired by cko (http://freshmeat.net/p/cko/), but independently
> written, later contributed forth and back.
>
> Already posted at: http://lkml.org/lkml/2007/4/1/162
>
> Signed-off-by: Jan Engelhardt <jengelh@gmx.de>
looks really good to me!
Reviewed-by: Ingo Molnar <mingo@elte.hu>
small nit:
+ vc->vc_color = printk_color;
+ update_attr(vc);
that should be in a set_vc_color() function and the new code should do:
+ set_vc_color(vc, vc->vc_color);
(and same at the other places that call update_attr() as well)
feature request: would be interesting to have a color table (defined in
the .config) dependent on message loglevel. That way KERN_CRIT messages
could be red, KERN_INFO ones white, etc.
Ingo
-
color in our linux
Really cool feature!
Colour not manually please.
We need a separation between plain text and coloured text.
What is the matter of grep with coloured texts?
The kernel MUST to printk / log plain text, and the virtual decorator of the virtual console MUST to change its color depending from some patterns and contexts.
OK$ => green("OK");
Fail$ => red("Fail");
Error$ => magenta("Error");
^Error => magenta("Error");
^Warning => orange("Warning");
core |-> virtual console |-> virtual decorator |-> virtual console |-> screen.
:)
Awesome!
Awesome! This is exactly what I always wanted!
Pretty rainbow colors!
This will make Linux much more fashionable!
I am definitely switching to Linux!
A very nice step in the good direction
However, linux needs more to appeal to the masses:
* a sexy female voice to comment the boot process
* a progress bar with a nice logo, ala windows xp
* the ability to have fun "screens of death" with pretty colours (the current Oopses are quite bland)
* more random crashes, so that users have something to complain with collegues during the coffee break
Well let's see... looking at
Well let's see... looking at my Nokia N800:
* a sexy female voice to comment the boot process
Got it.
* a progress bar with a nice logo, ala windows xp
Got it.
* the ability to have fun "screens of death" with pretty colours (the current Oopses are quite bland)
Hm. Haven't had an oops yet, so I can't tell...
* more random crashes, so that users have something to complain with collegues during the coffee break
Well my crashes aren't random, they're because of my crappy code. But they do give me something to complain about.
* a sexy female voice to
* a sexy female voice to comment the boot process
We got that (option)
* a progress bar with a nice logo, ala windows xp
We got that (option)
* the ability to have fun "screens of death" with pretty colours (the current Oopses are quite bland)
Not possible
* more random crashes, so that users have something to complain with collegues during the coffee break
These really rarely happen at all. I would say almost never, but only because it runs fine on my 6 different machines here, I cant say it will run on your Mac :>
Actually, current oopses are
Actually, current oopses are not bland - they are invisible, because people run x11 and Linux cannot display kernel messages "through" it.
* the ability to have fun
* the ability to have fun "screens of death" with pretty colours (the current Oopses are quite bland)
Can do that. While this is only the bootup sequency, an Oops could look the same.