diff --git a/drivers/syslog/Kconfig b/drivers/syslog/Kconfig index a098bf6aba..461a32c0fc 100644 --- a/drivers/syslog/Kconfig +++ b/drivers/syslog/Kconfig @@ -142,6 +142,12 @@ config SYSLOG_TIMESTAMP_BUFFER ---help--- Buffer size to store syslog formatted timestamps. +config SYSLOG_COLOR_OUTPUT + bool "Colored syslog output" + default n + ---help--- + Enables colored output in syslog, according to message priority. + config SYSLOG_PRIORITY bool "Prepend priority to syslog message" default n diff --git a/drivers/syslog/vsyslog.c b/drivers/syslog/vsyslog.c index d2bb5c1d20..728db13b10 100644 --- a/drivers/syslog/vsyslog.c +++ b/drivers/syslog/vsyslog.c @@ -176,6 +176,44 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap) ret += lib_sprintf(&stream.public, "[%6s] ", g_priority_str[priority]); #endif +#if defined(CONFIG_SYSLOG_COLOR_OUTPUT) + /* Set the terminal style according to message priority. */ + + switch (priority) + { + case LOG_EMERG: /* Red, Bold, Blinking */ + ret += lib_sprintf(&stream.public, "\e[31;1;5m"); + break; + + case LOG_ALERT: /* Red, Bold */ + ret += lib_sprintf(&stream.public, "\e[31;1m"); + break; + + case LOG_CRIT: /* Red, Bold */ + ret += lib_sprintf(&stream.public, "\e[31;1m"); + break; + + case LOG_ERR: /* Red */ + ret += lib_sprintf(&stream.public, "\e[31m"); + break; + + case LOG_WARNING: /* Yellow */ + ret += lib_sprintf(&stream.public, "\e[33m"); + break; + + case LOG_NOTICE: /* Bold */ + ret += lib_sprintf(&stream.public, "\e[1m"); + break; + + case LOG_INFO: /* Normal */ + break; + + case LOG_DEBUG: /* Dim */ + ret += lib_sprintf(&stream.public, "\e[2m"); + break; + } +#endif + #if defined(CONFIG_SYSLOG_PREFIX) /* Pre-pend the prefix, if available */ @@ -186,6 +224,12 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap) ret += lib_vsprintf(&stream.public, fmt, *ap); +#if defined(CONFIG_SYSLOG_COLOR_OUTPUT) + /* Reset the terminal style back to normal. */ + + ret += lib_sprintf(&stream.public, "\e[0m"); +#endif + #ifdef CONFIG_SYSLOG_BUFFER /* Flush and destroy the syslog stream buffer */