From 1ee6083de3733aab66bd78b93e7a8c055a431071 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sun, 26 Aug 2018 06:49:35 -0600 Subject: [PATCH] Squashed commit of the following: drivers/syslog: Channel configuration. Decouple SYSLOG_SERIAL_CONSOLE and ARCH_LOWPUTC. Since some hardware can output log to the special debug channel not serial. drivers/syslog/vsyslog.c: Support pre-pending a prefix string to log output if enabled. This very useful to identify which cpu send out the log in AMP SoC. drivers/syslog/vsyslog.c: Make timestamp output same as linux kernel. It's very useful if NuttX syslog retarget to Linux syslog. --- drivers/syslog/Kconfig | 13 +++++++++++++ drivers/syslog/syslog_channel.c | 2 +- drivers/syslog/syslog_consolechannel.c | 2 +- drivers/syslog/vsyslog.c | 12 ++++++++++-- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/drivers/syslog/Kconfig b/drivers/syslog/Kconfig index aeed64118e..a7556570ca 100644 --- a/drivers/syslog/Kconfig +++ b/drivers/syslog/Kconfig @@ -125,6 +125,19 @@ config SYSLOG_TIMESTAMP_REALTIME CLOCK_MONOTONIC, if enabled, will be used or the system timer is not. +config SYSLOG_PREFIX + bool "Prepend prefix to syslog message" + default n + ---help--- + Prepend prefix to syslog message. + +config SYSLOG_PREFIX_STRING + string "Prefix string" + depends on SYSLOG_PREFIX + default "" + ---help--- + The prefix string to be prepend. + config SYSLOG_SERIAL_CONSOLE bool default n diff --git a/drivers/syslog/syslog_channel.c b/drivers/syslog/syslog_channel.c index 107bdae0c3..3e3570eee2 100644 --- a/drivers/syslog/syslog_channel.c +++ b/drivers/syslog/syslog_channel.c @@ -57,7 +57,7 @@ * Private Function Prototypes ****************************************************************************/ -#if defined(CONFIG_SYSLOG_SERIAL_CONSOLE) && defined(CONFIG_ARCH_LOWPUTC) +#if defined(CONFIG_ARCH_LOWPUTC) # define HAVE_LOWPUTC #elif !defined(CONFIG_RAMLOG_SYSLOG) # define NEED_LOWPUTC diff --git a/drivers/syslog/syslog_consolechannel.c b/drivers/syslog/syslog_consolechannel.c index 1c338b0257..f3fb7e0596 100644 --- a/drivers/syslog/syslog_consolechannel.c +++ b/drivers/syslog/syslog_consolechannel.c @@ -54,7 +54,7 @@ ****************************************************************************/ #undef HAVE_LOWPUTC -#if defined(CONFIG_SYSLOG_SERIAL_CONSOLE) && defined(CONFIG_ARCH_LOWPUTC) +#if defined(CONFIG_ARCH_LOWPUTC) # define HAVE_LOWPUTC 1 #endif diff --git a/drivers/syslog/vsyslog.c b/drivers/syslog/vsyslog.c index 78a4120e8e..e6845573ae 100644 --- a/drivers/syslog/vsyslog.c +++ b/drivers/syslog/vsyslog.c @@ -131,13 +131,21 @@ 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 */ - (void)lib_sprintf(&stream.public, "[%6d.%06d]", + (void)lib_sprintf(&stream.public, "[%5d.%06d] ", ts.tv_sec, ts.tv_nsec/1000); #endif +#if defined(CONFIG_SYSLOG_PREFIX) + /* Pre-pend the prefix, if available */ + + ret = lib_sprintf(&stream.public, "%s", CONFIG_SYSLOG_PREFIX_STRING); +#else + ret = 0; +#endif + /* Generate the output */ - ret = lib_vsprintf(&stream.public, fmt, *ap); + ret += lib_vsprintf(&stream.public, fmt, *ap); #ifdef CONFIG_SYSLOG_BUFFER /* Flush and destroy the syslog stream buffer */