From 275b2e70a47c1d8e2bfd1797a7a283c1ba14d8c4 Mon Sep 17 00:00:00 2001 From: yinshengkai Date: Fri, 30 Dec 2022 17:09:45 +0800 Subject: [PATCH] syslog: fix extra line breaks in syslog when SYSLOG_COLOR_OUTPUT is enabled Signed-off-by: yinshengkai --- drivers/syslog/vsyslog.c | 5 +++++ include/nuttx/streams.h | 4 ++++ libs/libc/stream/lib_syslogstream.c | 9 ++------- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/syslog/vsyslog.c b/drivers/syslog/vsyslog.c index e5b2b1c541..336435b36f 100644 --- a/drivers/syslog/vsyslog.c +++ b/drivers/syslog/vsyslog.c @@ -222,6 +222,11 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap) ret += lib_vsprintf(&stream.public, fmt, *ap); + if (stream.last_ch != '\n') + { + lib_stream_putc(&stream.public, '\n'); + } + #if defined(CONFIG_SYSLOG_COLOR_OUTPUT) /* Reset the terminal style back to normal. */ diff --git a/include/nuttx/streams.h b/include/nuttx/streams.h index 979eedbeab..c49f6f0718 100644 --- a/include/nuttx/streams.h +++ b/include/nuttx/streams.h @@ -456,7 +456,11 @@ void lib_syslogstream_open(FAR struct lib_syslogstream_s *stream); * ****************************************************************************/ +#ifdef CONFIG_SYSLOG_BUFFER void lib_syslogstream_close(FAR struct lib_syslogstream_s *stream); +#else +# define lib_syslogstream_close(s) +#endif /**************************************************************************** * Name: lib_lzfoutstream diff --git a/libs/libc/stream/lib_syslogstream.c b/libs/libc/stream/lib_syslogstream.c index f981d7afbc..a77ca1c98f 100644 --- a/libs/libc/stream/lib_syslogstream.c +++ b/libs/libc/stream/lib_syslogstream.c @@ -214,16 +214,11 @@ void lib_syslogstream_open(FAR struct lib_syslogstream_s *stream) * ****************************************************************************/ +#ifdef CONFIG_SYSLOG_BUFFER void lib_syslogstream_close(FAR struct lib_syslogstream_s *stream) { DEBUGASSERT(stream != NULL); - if (stream->last_ch != '\n') - { - syslogstream_putc(&stream->public, '\n'); - } - -#ifdef CONFIG_SYSLOG_BUFFER /* Verify that there is an IOB attached (there should be) */ if (stream->iob != NULL) @@ -237,5 +232,5 @@ void lib_syslogstream_close(FAR struct lib_syslogstream_s *stream) iob_free(stream->iob); stream->iob = NULL; } -#endif } +#endif