* [PATCH] console: added colored print out of log levels @ 2018-02-21 8:26 Eugen Wiens 2018-02-22 7:56 ` Sascha Hauer 0 siblings, 1 reply; 3+ messages in thread From: Eugen Wiens @ 2018-02-21 8:26 UTC (permalink / raw) To: barebox; +Cc: Eugen Wiens When the system is booting the warnings and errors are not be quickly discovered. With this improvement the errors are colored red, the warnings yellow and the notices blue. Signed-off-by: Eugen Wiens <eugen.wiens@jumo.net> --- common/console_common.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/common/console_common.c b/common/console_common.c index 0202345a6..6d857d064 100644 --- a/common/console_common.c +++ b/common/console_common.c @@ -33,6 +33,18 @@ #ifndef CONFIG_CONSOLE_NONE +#define MAX_CHARACTERS_COLORED_LOG_LEVEL 20 +#define MAX_LOG_LEVEL MSG_NOTICE + +static const char colored_log_level[MAX_LOG_LEVEL+1][MAX_CHARACTERS_COLORED_LOG_LEVEL] = { + "\033[31mEMERG:\033[0m ", /* color red for log level MSG_EMERG */ + "\033[31mALERT:\033[0m ", /* color red for log level MSG_ALERT */ + "\033[31mCRITICAL:\033[0m ", /* color red for log level MSG_CRIT */ + "\033[31mERROR:\033[0m ", /* color red for log level MSG_ERR */ + "\033[33mWARNING:\033[0m ", /* color yellow for log level MSG_WARNING */ + "\033[34mNOTICE:\033[0m ", /* color blue for log level MSG_NOTICE */ +}; + int barebox_loglevel = CONFIG_DEFAULT_LOGLEVEL; LIST_HEAD(barebox_logbuf); @@ -102,6 +114,15 @@ nolog: puts(str); } +static void print_colored_log_level(const int level) +{ + if (console_allow_color()) { + if (level <= MAX_LOG_LEVEL) { + pr_puts(level, colored_log_level[level]); + } + } +} + int pr_print(int level, const char *fmt, ...) { va_list args; @@ -111,6 +132,8 @@ int pr_print(int level, const char *fmt, ...) if (!IS_ENABLED(CONFIG_LOGBUF) && level > barebox_loglevel) return 0; + print_colored_log_level(level); + va_start(args, fmt); i = vsprintf(printbuffer, fmt, args); va_end(args); @@ -129,6 +152,8 @@ int dev_printf(int level, const struct device_d *dev, const char *format, ...) if (!IS_ENABLED(CONFIG_LOGBUF) && level > barebox_loglevel) return 0; + print_colored_log_level(level); + if (dev->driver && dev->driver->name) ret += sprintf(printbuffer, "%s ", dev->driver->name); -- 2.16.1 Diese E-Mail kann vertrauliche und/oder rechtlich geschützte Informationen beinhalten und ist ausschließlich für die im Verteiler genannten Personen bestimmt. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail sind nicht gestattet. Bitte benachrichtigen Sie uns gegebenenfalls telefonisch oder mit Antwort-Mail, falls Sie nicht der richtige Adressat dieser E-Mail sind. Bitte löschen Sie diese Nachricht und alle Anhänge dazu unverzüglich. Falls nicht ausdrücklich vermerkt, ist diese E-Mail keine rechtlich bindende Vereinbarung. Kommanditgesellschaft: JUMO GmbH & Co. KG, Sitz: 36039 Fulda, Amtsgericht Fulda HRA 302, Persönlich haftende Gesellschafterin: M. K. JUCHHEIM GmbH, Sitz: 36039 Fulda, Amtsgericht Fulda HRB 17, Geschäftsführer: Dipl.-Ing. Bernhard Juchheim, Dipl.-Kfm. Michael Juchheim Ust.-Id.-Nr.: DE 112411234 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] console: added colored print out of log levels 2018-02-21 8:26 [PATCH] console: added colored print out of log levels Eugen Wiens @ 2018-02-22 7:56 ` Sascha Hauer 2018-02-22 15:16 ` Antwort: " Eugen.Wiens 0 siblings, 1 reply; 3+ messages in thread From: Sascha Hauer @ 2018-02-22 7:56 UTC (permalink / raw) To: Eugen Wiens; +Cc: barebox Hi Eugen, On Wed, Feb 21, 2018 at 09:26:38AM +0100, Eugen Wiens wrote: > When the system is booting the warnings and errors are not be quickly > discovered. With this improvement the errors are colored red, the > warnings yellow and the notices blue. I polished the patch a bit to match the barebox coding style. However, there is still one detail I do not like. Some pr_err() messages have pr_err("ERROR: bla\n"). With colored console we now get: "ERROR: ERROR: bla". Now we could say we remove all "ERROR:" strings from the callers, but then we would have no "ERROR:" at all when colored console is disabled. The obvious solution would be to always add "ERROR:" to the messages, be it colored or not. I applied it for now, but I think this is not the final solution. Sascha --------------------------------8<----------------------------------- From a019f725ab48536a4bb93ec2dea319d9fc5206c5 Mon Sep 17 00:00:00 2001 From: Eugen Wiens <eugen.wiens@jumo.net> Date: Wed, 21 Feb 2018 09:26:38 +0100 Subject: [PATCH] console: added colored print out of log levels When the system is booting the warnings and errors are not be quickly discovered. With this improvement the errors are colored red, the warnings yellow and the notices blue. Signed-off-by: Eugen Wiens <eugen.wiens@jumo.net> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> --- common/console_common.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/common/console_common.c b/common/console_common.c index 0202345a62..00e020bd35 100644 --- a/common/console_common.c +++ b/common/console_common.c @@ -33,6 +33,15 @@ #ifndef CONFIG_CONSOLE_NONE +static const char *colored_log_level[] = { + [MSG_EMERG] = "\033[31mEMERG:\033[0m ", /* red */ + [MSG_ALERT] = "\033[31mALERT:\033[0m ", /* red */ + [MSG_CRIT] = "\033[31mCRITICAL:\033[0m ", /* red */ + [MSG_ERR] = "\033[31mERROR:\033[0m ", /* red */ + [MSG_WARNING] = "\033[33mWARNING:\033[0m ", /* yellow */ + [MSG_NOTICE] = "\033[34mNOTICE:\033[0m ", /* blue */ +}; + int barebox_loglevel = CONFIG_DEFAULT_LOGLEVEL; LIST_HEAD(barebox_logbuf); @@ -102,6 +111,18 @@ nolog: puts(str); } +static void print_colored_log_level(const int level) +{ + if (!console_allow_color()) + return; + if (level >= ARRAY_SIZE(colored_log_level)) + return; + if (!colored_log_level[level]) + return; + + pr_puts(level, colored_log_level[level]); +} + int pr_print(int level, const char *fmt, ...) { va_list args; @@ -111,6 +132,8 @@ int pr_print(int level, const char *fmt, ...) if (!IS_ENABLED(CONFIG_LOGBUF) && level > barebox_loglevel) return 0; + print_colored_log_level(level); + va_start(args, fmt); i = vsprintf(printbuffer, fmt, args); va_end(args); @@ -129,6 +152,8 @@ int dev_printf(int level, const struct device_d *dev, const char *format, ...) if (!IS_ENABLED(CONFIG_LOGBUF) && level > barebox_loglevel) return 0; + print_colored_log_level(level); + if (dev->driver && dev->driver->name) ret += sprintf(printbuffer, "%s ", dev->driver->name); -- 2.16.1 -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 3+ messages in thread
* Antwort: Re: [PATCH] console: added colored print out of log levels 2018-02-22 7:56 ` Sascha Hauer @ 2018-02-22 15:16 ` Eugen.Wiens 0 siblings, 0 replies; 3+ messages in thread From: Eugen.Wiens @ 2018-02-22 15:16 UTC (permalink / raw) To: Sascha Hauer; +Cc: barebox Hi Sascha, Sascha Hauer <s.hauer@pengutronix.de> schrieb am 22.02.2018 08:56:02: > Von: Sascha Hauer <s.hauer@pengutronix.de> > An: Eugen Wiens <eugen.wiens@jumo.net> > Kopie: barebox@lists.infradead.org > Datum: 22.02.2018 08:56 > Betreff: Re: [PATCH] console: added colored print out of log levels > > Hi Eugen, > > On Wed, Feb 21, 2018 at 09:26:38AM +0100, Eugen Wiens wrote: > > When the system is booting the warnings and errors are not be quickly > > discovered. With this improvement the errors are colored red, the > > warnings yellow and the notices blue. > > I polished the patch a bit to match the barebox coding style. That sounds good for me and I will working on me, so that the next patches will be more compliant to barebox coding style. > However, > there is still one detail I do not like. Some pr_err() messages have > pr_err("ERROR: bla\n"). With colored console we now get: > "ERROR: ERROR: bla". Now we could say we remove all "ERROR:" strings > from the callers, but then we would have no "ERROR:" at all when > colored console is disabled. The obvious solution would be to always > add "ERROR:" to the messages, be it colored or not. > I applied it for now, but I think this is not the final solution. cool. Thanks. > > Sascha > > --------------------------------8<----------------------------------- > > From a019f725ab48536a4bb93ec2dea319d9fc5206c5 Mon Sep 17 00:00:00 2001 > From: Eugen Wiens <eugen.wiens@jumo.net> > Date: Wed, 21 Feb 2018 09:26:38 +0100 > Subject: [PATCH] console: added colored print out of log levels > > When the system is booting the warnings and errors are not be > quickly discovered. With this improvement the errors are colored > red, the warnings yellow and the notices blue. > > Signed-off-by: Eugen Wiens <eugen.wiens@jumo.net> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> > --- > common/console_common.c | 25 +++++++++++++++++++++++++ > 1 file changed, 25 insertions(+) > > diff --git a/common/console_common.c b/common/console_common.c > index 0202345a62..00e020bd35 100644 > --- a/common/console_common.c > +++ b/common/console_common.c > @@ -33,6 +33,15 @@ > > #ifndef CONFIG_CONSOLE_NONE > > +static const char *colored_log_level[] = { > + [MSG_EMERG] = "\033[31mEMERG:\033[0m ", /* red */ > + [MSG_ALERT] = "\033[31mALERT:\033[0m ", /* red */ > + [MSG_CRIT] = "\033[31mCRITICAL:\033[0m ", /* red */ > + [MSG_ERR] = "\033[31mERROR:\033[0m ", /* red */ > + [MSG_WARNING] = "\033[33mWARNING:\033[0m ", /* yellow */ > + [MSG_NOTICE] = "\033[34mNOTICE:\033[0m ", /* blue */ > +}; > + > int barebox_loglevel = CONFIG_DEFAULT_LOGLEVEL; > > LIST_HEAD(barebox_logbuf); > @@ -102,6 +111,18 @@ nolog: > puts(str); > } > > +static void print_colored_log_level(const int level) > +{ > + if (!console_allow_color()) > + return; > + if (level >= ARRAY_SIZE(colored_log_level)) > + return; > + if (!colored_log_level[level]) > + return; > + > + pr_puts(level, colored_log_level[level]); > +} > + > int pr_print(int level, const char *fmt, ...) > { > va_list args; > @@ -111,6 +132,8 @@ int pr_print(int level, const char *fmt, ...) > if (!IS_ENABLED(CONFIG_LOGBUF) && level > barebox_loglevel) > return 0; > > + print_colored_log_level(level); > + > va_start(args, fmt); > i = vsprintf(printbuffer, fmt, args); > va_end(args); > @@ -129,6 +152,8 @@ int dev_printf(int level, const struct device_d > *dev, const char *format, ...) > if (!IS_ENABLED(CONFIG_LOGBUF) && level > barebox_loglevel) > return 0; > > + print_colored_log_level(level); > + > if (dev->driver && dev->driver->name) > ret += sprintf(printbuffer, "%s ", dev->driver->name); > > -- > 2.16.1 > > -- > Pengutronix e.K. | | > Industrial Linux Solutions | http://www.pengutronix.de/ | > Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | > Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | Mit freundlichen Grüßen / Best regards JUMO GmbH & Co. KG Entwicklung - Vorentwicklung Plattformen / Predevelopment Platforms i. A. Dipl.-Ing.(FH) Eugen Wiens Tel: +49 661 6003 9577 Fax: +49 661 6003 88 9577 Adresse: Moritz-Juchheim-Straße 1 36039 Fulda, Germany E-Mail: eugen.wiens@jumo.net Internet: http://www.jumo.net Diese E-Mail kann vertrauliche und/oder rechtlich geschützte Informationen beinhalten und ist ausschließlich für die im Verteiler genannten Personen bestimmt. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail sind nicht gestattet. Bitte benachrichtigen Sie uns gegebenenfalls telefonisch oder mit Antwort-Mail, falls Sie nicht der richtige Adressat dieser E-Mail sind. Bitte löschen Sie diese Nachricht und alle Anhänge dazu unverzüglich. Falls nicht ausdrücklich vermerkt, ist diese E-Mail keine rechtlich bindende Vereinbarung. Kommanditgesellschaft: JUMO GmbH & Co. KG, Sitz: 36039 Fulda, Amtsgericht Fulda HRA 302, Persönlich haftende Gesellschafterin: M. K. JUCHHEIM GmbH, Sitz: 36039 Fulda, Amtsgericht Fulda HRB 17, Geschäftsführer: Dipl.-Ing. Bernhard Juchheim, Dipl.-Kfm. Michael Juchheim Ust.-Id.-Nr.: DE 112411234 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-02-22 15:17 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-02-21 8:26 [PATCH] console: added colored print out of log levels Eugen Wiens 2018-02-22 7:56 ` Sascha Hauer 2018-02-22 15:16 ` Antwort: " Eugen.Wiens
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox