Colored Kernel Output for 2.6.25 - Kernel
This is a discussion on Colored Kernel Output for 2.6.25 - Kernel ; This is CKO rediffed for 2.6.25. It is advised (but should not be
mandatory) to slurp in "vt: fix background color on line feed" first as
I removed the linefeed-color hack from CKO since the lf thing really
is a ...
-
Colored Kernel Output for 2.6.25
This is CKO rediffed for 2.6.25. It is advised (but should not be
mandatory) to slurp in "vt: fix background color on line feed" first as
I removed the linefeed-color hack from CKO since the lf thing really
is a separate issue that also happens outside CKO.
Nothing new really, as usual you can give any of the 8 kernel logging
levels a color from the 16-color palette. Of course it all defaults to
the defaults you have seen in the past 10+ years, so no worries.
If anybody wants to apply it, the better.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
-
[1/3] Re: Colored Kernel Output for 2.6.25
commit 15e3809bd3b6596158263301a344c1fdf281e11d
Author: Jan Engelhardt
Date: Sun Apr 27 03:17:51 2008 +0200
Colored kernel message output (1/3)
This patch makes it possible to give kernel messages a selectable
color. It can be chosen at compile time, overridden at boot time,
and changed at run time.
References:
http://lkml.org/lkml/2007/4/1/162
http://lkml.org/lkml/2007/10/5/199
http://lkml.org/lkml/2007/10/6/88
http://lkml.org/lkml/2007/10/6/89
Signed-off-by: Jan Engelhardt
---
drivers/char/Kconfig | 43 ++++++++++++++++++++++++++++++++++++++++++
drivers/char/vt.c | 21 ++++++++++++++++++++
2 files changed, 64 insertions(+), 0 deletions(-)
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 47c6be8..a55a1c9 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -58,6 +58,49 @@ config VT_CONSOLE
If unsure, say Y.
+config VT_CKO
+ bool "Colored kernel message output"
+ depends on VT_CONSOLE
+ ---help---
+ This option enables kernel messages to be emitted in
+ colors other than the default.
+ This option enlarges your kernel by approximately 1/2 KB.
+
+ If unsure, say N.
+
+config VT_PRINTK_COLOR
+ hex "Colored kernel message output"
+ range 0x00 0xFF
+ depends on VT_CKO
+ default 0x07
+ ---help---
+ This option defines with which color kernel messages will be
+ printed to the console.
+
+ The value you need to enter here is the value is composed
+ (OR-ed) of a foreground and a background color.
+
+ Foreground:
+ 0x00 = black, 0x08 = dark gray,
+ 0x01 = red, 0x09 = light red,
+ 0x02 = green, 0x0A = light green,
+ 0x03 = brown, 0x0B = yellow,
+ 0x04 = blue, 0x0C = light blue,
+ 0x05 = magenta, 0x0D = light magenta,
+ 0x06 = cyan, 0x0E = light cyan,
+ 0x07 = gray, 0x0F = white,
+
+ (Foreground colors 0x08 to 0x0F do not work when a VGA
+ console font with 512 glyphs is used.)
+
+ Background:
+ 0x00 = black, 0x40 = blue,
+ 0x10 = red, 0x50 = magenta,
+ 0x20 = green, 0x60 = cyan,
+ 0x30 = brown, 0x70 = gray,
+
+ For example, 0x1F would yield white on red.
+
config HW_CONSOLE
bool
depends on VT && !S390 && !UML
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index 159c9e2..cf61236 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -73,6 +73,7 @@
*/
#include
+#include
#include
#include
#include
@@ -2392,6 +2393,24 @@ struct tty_driver *console_driver;
#ifdef CONFIG_VT_CONSOLE
+#ifdef CONFIG_VT_CKO
+static unsigned int printk_color __read_mostly = CONFIG_VT_PRINTK_COLOR;
+module_param(printk_color, uint, S_IRUGO | S_IWUSR);
+
+static void vc_set_color(struct vc_data *vc, unsigned char color)
+{
+ vc->vc_color = color_table[color & 0xF] |
+ (color_table[(color >> 4) & 0x7] << 4) |
+ (color & 0x80);
+ update_attr(vc);
+}
+#else
+static const unsigned int printk_color;
+static inline void vc_set_color(const struct vc_data *vc, unsigned char c)
+{
+}
+#endif
+
/*
* Console on virtual terminal
*
@@ -2434,6 +2453,7 @@ static void vt_console_print(struct console *co, const char *b, unsigned count)
hide_cursor(vc);
start = (ushort *)vc->vc_pos;
+ vc_set_color(vc, printk_color);
/* Contrived structure to try to emulate original need_wrap behaviour
* Problems caused when we have need_wrap set on '\n' character */
@@ -2482,6 +2502,7 @@ static void vt_console_print(struct console *co, const char *b, unsigned count)
}
}
set_cursor(vc);
+ vc_set_color(vc, vc->vc_def_color);
notify_update(vc);
quit:
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
-
[3/3] Re: Colored Kernel Output for 2.6.25
commit 872d296f6521ecdcbddd3ffe74d7565abfa8c3fa
Author: Jan Engelhardt
Date: Sun Apr 27 03:55:17 2008 +0200
Colored kernel message output (3/3)
Ref-From: Miguel Botón
I modified your lastest patch a little bit so now you can set the
message color for each log level in the kernel config.
References: http://lkml.org/lkml/2007/10/6/105
Signed-off-by: Jan Engelhardt
---
drivers/char/Kconfig | 86 +++++++++++++++++++++++++++++++++++------
drivers/char/vt.c | 16 ++++----
2 files changed, 81 insertions(+), 21 deletions(-)
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 3f5877e..600c75a 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -58,28 +58,20 @@ config VT_CONSOLE
If unsure, say Y.
-config VT_CKO
+menuconfig VT_CKO
bool "Colored kernel message output"
depends on VT_CONSOLE
---help---
This option enables kernel messages to be emitted in
colors other than the default.
+ You can also change the colors at run-time, or set them at boot-time
+ using the "vt.printk_color" option.
+
This option enlarges your kernel by approximately 1/2 KB.
If unsure, say N.
-config VT_PRINTK_COLOR
- hex "Colored kernel message output"
- range 0x00 0xFF
- depends on VT_CKO
- default 0x07
- ---help---
- This option defines with which color kernel messages will be
- printed to the console. This applies to all log levels.
- You can change the colors at run-time, or set them at boot-time
- using the "vt.printk_color" option.
-
- The value you need to enter here is the value is composed
+ The value you need to enter is the value is composed
(OR-ed) of a foreground and a background color.
Foreground:
@@ -103,6 +95,74 @@ config VT_PRINTK_COLOR
For example, 0x1F would yield white on red.
+if VT_CKO
+
+config VT_PRINTK_EMERG_COLOR
+ hex 'Color for "emergency" level'
+ range 0x00 0xFF
+ default 0x07
+ ---help---
+ This option defines in which color kernel emergency messages
+ will be printed to the console.
+
+config VT_PRINTK_ALERT_COLOR
+ hex 'Color for "alert" level'
+ range 0x00 0xFF
+ default 0x07
+ ---help---
+ This option defines in which color kernel alert messages
+ will be printed to the console.
+
+config VT_PRINTK_CRIT_COLOR
+ hex 'Color for "critical" level'
+ range 0x00 0xFF
+ default 0x07
+ ---help---
+ This option defines in which color critical kernel messages
+ will be printed to the console.
+
+config VT_PRINTK_ERROR_COLOR
+ hex 'Color for "error" level'
+ range 0x00 0xFF
+ default 0x07
+ ---help---
+ This option defines in which color kernel error messages
+ will be printed to the console.
+
+config VT_PRINTK_WARNING_COLOR
+ hex 'Color for "warning" level'
+ range 0x00 0xFF
+ default 0x07
+ ---help---
+ This option defines in which color kernel warning messages
+ will be printed to the console.
+
+config VT_PRINTK_NOTICE_COLOR
+ hex 'Color for "notice" level'
+ range 0x00 0xFF
+ default 0x07
+ ---help---
+ This option defines in which color kernel notices
+ will be printed to the console.
+
+config VT_PRINTK_INFO_COLOR
+ hex 'Color for "info" level'
+ range 0x00 0xFF
+ default 0x07
+ ---help---
+ This option defines in which color informational kernel messages
+ will be printed to the console.
+
+config VT_PRINTK_DEBUG_COLOR
+ hex 'Color for "debug" level'
+ range 0x00 0xFF
+ default 0x07
+ ---help---
+ This option defines in which color kernel debugging messages
+ will be printed to the console.
+
+endif # VT_CKO
+
config HW_CONSOLE
bool
depends on VT && !S390 && !UML
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index 75ca0cf..a3f2ff3 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -2395,14 +2395,14 @@ struct tty_driver *console_driver;
#ifdef CONFIG_VT_CKO
static unsigned int printk_color[8] __read_mostly = {
- CONFIG_VT_PRINTK_COLOR, /* KERN_EMERG */
- CONFIG_VT_PRINTK_COLOR, /* KERN_ALERT */
- CONFIG_VT_PRINTK_COLOR, /* KERN_CRIT */
- CONFIG_VT_PRINTK_COLOR, /* KERN_ERR */
- CONFIG_VT_PRINTK_COLOR, /* KERN_WARNING */
- CONFIG_VT_PRINTK_COLOR, /* KERN_NOTICE */
- CONFIG_VT_PRINTK_COLOR, /* KERN_INFO */
- CONFIG_VT_PRINTK_COLOR, /* KERN_DEBUG */
+ CONFIG_VT_PRINTK_EMERG_COLOR,
+ CONFIG_VT_PRINTK_ALERT_COLOR,
+ CONFIG_VT_PRINTK_CRIT_COLOR,
+ CONFIG_VT_PRINTK_ERROR_COLOR,
+ CONFIG_VT_PRINTK_WARNING_COLOR,
+ CONFIG_VT_PRINTK_NOTICE_COLOR,
+ CONFIG_VT_PRINTK_INFO_COLOR,
+ CONFIG_VT_PRINTK_DEBUG_COLOR,
};
module_param_array(printk_color, uint, NULL, S_IRUGO | S_IWUSR);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
-
[2/3] Re: Colored Kernel Output for 2.6.25
commit 09f4590103d5ae8cd3e0a90e801b60cd1339cf12
Author: Jan Engelhardt
Date: Sun Apr 27 03:50:25 2008 +0200
Colored kernel message output (2/3)
By popular request, this patch adds per-loglevel coloring. The user
may set values using vt.printk_color= or by modifying the sysfs file
in the running system.
Signed-off-by: Jan Engelhardt
---
arch/x86/kernel/early_printk.c | 11 +++++++----
drivers/char/Kconfig | 4 +++-
drivers/char/vt.c | 28 ++++++++++++++++++++++------
drivers/net/netconsole.c | 3 ++-
drivers/serial/8250.c | 3 ++-
drivers/serial/8250_early.c | 3 ++-
include/linux/console.h | 3 ++-
kernel/printk.c | 12 +++++++-----
8 files changed, 47 insertions(+), 20 deletions(-)
diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
index cff84cd..ba137a4 100644
--- a/arch/x86/kernel/early_printk.c
+++ b/arch/x86/kernel/early_printk.c
@@ -15,7 +15,8 @@
static int max_ypos = 25, max_xpos = 80;
static int current_ypos = 25, current_xpos = 0;
-static void early_vga_write(struct console *con, const char *str, unsigned n)
+static void early_vga_write(struct console *con, const char *str, unsigned n,
+ unsigned int loglevel)
{
char c;
int i, k, j;
@@ -84,7 +85,8 @@ static int early_serial_putc(unsigned char ch)
return timeout ? 0 : -1;
}
-static void early_serial_write(struct console *con, const char *s, unsigned n)
+static void early_serial_write(struct console *con, const char *s, unsigned n,
+ unsigned int loglevel)
{
while (*s && n-- > 0) {
if (*s == '\n')
@@ -180,7 +182,8 @@ static void __init simnow_init(char *str)
simnow_fd = simnow(XOPEN, (unsigned long)fn, O_WRONLY|O_APPEND|O_CREAT, 0644);
}
-static void simnow_write(struct console *con, const char *s, unsigned n)
+static void simnow_write(struct console *con, const char *s, unsigned n,
+ unsigned int loglevel)
{
simnow(XWRITE, simnow_fd, (unsigned long)s, n);
}
@@ -204,7 +207,7 @@ void early_printk(const char *fmt, ...)
va_start(ap,fmt);
n = vscnprintf(buf,512,fmt,ap);
- early_console->write(early_console,buf,n);
+ early_console->write(early_console, buf, n, 0);
va_end(ap);
}
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index a55a1c9..3f5877e 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -75,7 +75,9 @@ config VT_PRINTK_COLOR
default 0x07
---help---
This option defines with which color kernel messages will be
- printed to the console.
+ printed to the console. This applies to all log levels.
+ You can change the colors at run-time, or set them at boot-time
+ using the "vt.printk_color" option.
The value you need to enter here is the value is composed
(OR-ed) of a foreground and a background color.
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index cf61236..75ca0cf 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -2394,8 +2394,17 @@ struct tty_driver *console_driver;
#ifdef CONFIG_VT_CONSOLE
#ifdef CONFIG_VT_CKO
-static unsigned int printk_color __read_mostly = CONFIG_VT_PRINTK_COLOR;
-module_param(printk_color, uint, S_IRUGO | S_IWUSR);
+static unsigned int printk_color[8] __read_mostly = {
+ CONFIG_VT_PRINTK_COLOR, /* KERN_EMERG */
+ CONFIG_VT_PRINTK_COLOR, /* KERN_ALERT */
+ CONFIG_VT_PRINTK_COLOR, /* KERN_CRIT */
+ CONFIG_VT_PRINTK_COLOR, /* KERN_ERR */
+ CONFIG_VT_PRINTK_COLOR, /* KERN_WARNING */
+ CONFIG_VT_PRINTK_COLOR, /* KERN_NOTICE */
+ CONFIG_VT_PRINTK_COLOR, /* KERN_INFO */
+ CONFIG_VT_PRINTK_COLOR, /* KERN_DEBUG */
+};
+module_param_array(printk_color, uint, NULL, S_IRUGO | S_IWUSR);
static void vc_set_color(struct vc_data *vc, unsigned char color)
{
@@ -2405,7 +2414,7 @@ static void vc_set_color(struct vc_data *vc, unsigned char color)
update_attr(vc);
}
#else
-static const unsigned int printk_color;
+static const unsigned int printk_color[8];
static inline void vc_set_color(const struct vc_data *vc, unsigned char c)
{
}
@@ -2417,10 +2426,11 @@ static inline void vc_set_color(const struct vc_data *vc, unsigned char c)
* The console must be locked when we get here.
*/
-static void vt_console_print(struct console *co, const char *b, unsigned count)
+static void vt_console_print(struct console *co, const char *b,
+ unsigned int count, unsigned int loglevel)
{
struct vc_data *vc = vc_cons[fg_console].d;
- unsigned char c;
+ unsigned char current_color, c;
static DEFINE_SPINLOCK(printing_lock);
const ushort *start;
ushort cnt = 0;
@@ -2453,7 +2463,13 @@ static void vt_console_print(struct console *co, const char *b, unsigned count)
hide_cursor(vc);
start = (ushort *)vc->vc_pos;
- vc_set_color(vc, printk_color);
+
+ /*
+ * We always get a valid loglevel - <8> and "no level" is transformed
+ * to <4> in the typical kernel.
+ */
+ current_color = printk_color[loglevel];
+ vc_set_color(vc, current_color);
/* Contrived structure to try to emulate original need_wrap behaviour
* Problems caused when we have need_wrap set on '\n' character */
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 665341e..ae04e77 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -694,7 +694,8 @@ static struct notifier_block netconsole_netdev_notifier = {
.notifier_call = netconsole_netdev_event,
};
-static void write_msg(struct console *con, const char *msg, unsigned int len)
+static void write_msg(struct console *con, const char *msg, unsigned int len,
+ unsigned int loglevel)
{
int frag, left;
unsigned long flags;
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index 77f7a7f..21a0ebf 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -2466,7 +2466,8 @@ static void serial8250_console_putchar(struct uart_port *port, int ch)
* The console_lock must be held when we get here.
*/
static void
-serial8250_console_write(struct console *co, const char *s, unsigned int count)
+serial8250_console_write(struct console *co, const char *s, unsigned int count,
+ unsigned int loglevel)
{
struct uart_8250_port *up = &serial8250_ports[co->index];
unsigned long flags;
diff --git a/drivers/serial/8250_early.c b/drivers/serial/8250_early.c
index 38776e8..88aa01c 100644
--- a/drivers/serial/8250_early.c
+++ b/drivers/serial/8250_early.c
@@ -83,7 +83,8 @@ static void __init serial_putc(struct uart_port *port, int c)
}
static void __init early_serial8250_write(struct console *console,
- const char *s, unsigned int count)
+ const char *s, unsigned int count,
+ unsigned int loglevel)
{
struct uart_port *port = &early_device.port;
unsigned int ier;
diff --git a/include/linux/console.h b/include/linux/console.h
index a5f88a6..23626e6 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -94,7 +94,8 @@ void give_up_console(const struct consw *sw);
struct console {
char name[16];
- void (*write)(struct console *, const char *, unsigned);
+ void (*write)(struct console *, const char *,
+ unsigned int, unsigned int);
int (*read)(struct console *, char *, unsigned);
struct tty_driver *(*device)(struct console *, int *);
void (*unblank)(void);
diff --git a/kernel/printk.c b/kernel/printk.c
index bdd4ea8..809ba4b 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -435,7 +435,8 @@ asmlinkage long sys_syslog(int type, char __user *buf, int len)
/*
* Call the console drivers on a range of log_buf
*/
-static void __call_console_drivers(unsigned start, unsigned end)
+static void __call_console_drivers(unsigned int start, unsigned int end,
+ unsigned int loglevel)
{
struct console *con;
@@ -443,7 +444,7 @@ static void __call_console_drivers(unsigned start, unsigned end)
if ((con->flags & CON_ENABLED) && con->write &&
(cpu_online(smp_processor_id()) ||
(con->flags & CON_ANYTIME)))
- con->write(con, &LOG_BUF(start), end - start);
+ con->write(con, &LOG_BUF(start), end - start, loglevel);
}
}
@@ -470,10 +471,11 @@ static void _call_console_drivers(unsigned start,
if ((start & LOG_BUF_MASK) > (end & LOG_BUF_MASK)) {
/* wrapped write */
__call_console_drivers(start & LOG_BUF_MASK,
- log_buf_len);
- __call_console_drivers(0, end & LOG_BUF_MASK);
+ log_buf_len, msg_log_level);
+ __call_console_drivers(0, end & LOG_BUF_MASK,
+ msg_log_level);
} else {
- __call_console_drivers(start, end);
+ __call_console_drivers(start, end, msg_log_level);
}
}
}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/