From cf8521e6dece1082d9ff5dea32846f30a244ac6e Mon Sep 17 00:00:00 2001 From: Matias N Date: Wed, 10 Mar 2021 17:21:28 -0300 Subject: [PATCH] syslog: add option to prefix process name --- drivers/syslog/Kconfig | 20 +++++++++++++------- drivers/syslog/vsyslog.c | 18 ++++++++++++++---- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/drivers/syslog/Kconfig b/drivers/syslog/Kconfig index 7664a63981..1f8aa2b0ce 100644 --- a/drivers/syslog/Kconfig +++ b/drivers/syslog/Kconfig @@ -142,20 +142,20 @@ 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 ---help--- Prepend log priority (severity) to syslog message. +config SYSLOG_PROCESS_NAME + bool "Prepend process name to syslog message" + default n + ---help--- + Prepend Process name to syslog message. + config SYSLOG_PROCESSID - bool "Prepend Process ID to syslog message" + bool "Prepend process ID to syslog message" default n ---help--- Prepend Process ID to syslog message. @@ -173,6 +173,12 @@ config SYSLOG_PREFIX_STRING ---help--- The prefix string to be prepend. +config SYSLOG_COLOR_OUTPUT + bool "Colored syslog output" + default n + ---help--- + Enables colored output in syslog, according to message priority. + choice prompt "System log device" default SYSLOG_CONSOLE if !ARCH_LOWPUTC diff --git a/drivers/syslog/vsyslog.c b/drivers/syslog/vsyslog.c index fef9a0fe85..80c65b120d 100644 --- a/drivers/syslog/vsyslog.c +++ b/drivers/syslog/vsyslog.c @@ -67,6 +67,9 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap) { struct lib_syslogstream_s stream; int ret; +#if CONFIG_TASK_NAME_SIZE > 0 && defined(CONFIG_SYSLOG_PROCESS_NAME) + struct tcb_s *tcb; +#endif #if defined(CONFIG_SYSLOG_TIMESTAMP_FORMATTED) time_t time; struct tm tm; @@ -131,7 +134,7 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap) } #if defined(CONFIG_SYSLOG_TIMESTAMP) - /* Pre-pend the message with the current time, if available */ + /* Prepend the message with the current time, if available */ #if defined(CONFIG_SYSLOG_TIMESTAMP_FORMATTED) time = ts.tv_sec; @@ -157,7 +160,7 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap) #endif #if defined(CONFIG_SYSLOG_PROCESSID) - /* Pre-pend the Process ID */ + /* Prepend the Process ID */ ret += lib_sprintf(&stream.public, "[%2d] ", (int)getpid()); #endif @@ -201,17 +204,24 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap) #endif #if defined(CONFIG_SYSLOG_PRIORITY) - /* Pre-pend the message priority. */ + /* Prepend the message priority. */ ret += lib_sprintf(&stream.public, "[%6s] ", g_priority_str[priority]); #endif #if defined(CONFIG_SYSLOG_PREFIX) - /* Pre-pend the prefix, if available */ + /* Prepend the prefix, if available */ ret += lib_sprintf(&stream.public, "%s", CONFIG_SYSLOG_PREFIX_STRING); #endif +#if CONFIG_TASK_NAME_SIZE > 0 && defined(CONFIG_SYSLOG_PROCESS_NAME) + /* Prepend the process name */ + + tcb = nxsched_get_tcb(getpid()); + ret += lib_sprintf(&stream.public, "%s: ", tcb->name); +#endif + /* Generate the output */ ret += lib_vsprintf(&stream.public, fmt, *ap);