From 7828dff2ea678d585c2df97488ad0819a799eeea Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Fri, 9 Nov 2018 08:49:07 -0600 Subject: [PATCH] drivers/syslog: syslog_initialize initialize dev/syslog too and call syslog to add the prefix and timestamp --- drivers/syslog/syslog.h | 18 ++++++++++++++++++ drivers/syslog/syslog_chardev.c | 5 +++-- drivers/syslog/syslog_initialize.c | 7 +++++++ include/nuttx/syslog/syslog.h | 18 ------------------ 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/drivers/syslog/syslog.h b/drivers/syslog/syslog.h index 090ae6aba4..cfc97dab07 100644 --- a/drivers/syslog/syslog.h +++ b/drivers/syslog/syslog.h @@ -187,6 +187,24 @@ int syslog_dev_channel(void); int syslog_console_channel(void); #endif +/**************************************************************************** + * Name: syslog_register + * + * Description: + * Register a simple character driver at /dev/syslog whose write() method + * will transfer data to the SYSLOG device. This can be useful if, for + * example, you want to redirect the output of a program to the SYSLOG. + * + * NOTE that unlike other syslog output, this data is unformatted raw + * byte output with no time-stamping or any other SYSLOG features + * supported. + * + ****************************************************************************/ + +#ifdef CONFIG_SYSLOG_CHARDEV +void syslog_register(void); +#endif + /**************************************************************************** * Name: syslog_add_intbuffer * diff --git a/drivers/syslog/syslog_chardev.c b/drivers/syslog/syslog_chardev.c index 0db139ab82..bbb1194be6 100644 --- a/drivers/syslog/syslog_chardev.c +++ b/drivers/syslog/syslog_chardev.c @@ -46,7 +46,7 @@ #include #include -#include +#include #include "syslog.h" @@ -90,7 +90,8 @@ static const struct file_operations syslog_fops = static ssize_t syslog_chardev_write(FAR struct file *filep, FAR const char *buffer, size_t len) { - return syslog_write(buffer, len); + syslog(LOG_INFO, "%.*s", (int)len, buffer); + return len; } /**************************************************************************** diff --git a/drivers/syslog/syslog_initialize.c b/drivers/syslog/syslog_initialize.c index 3c408e61db..87c575b2bb 100644 --- a/drivers/syslog/syslog_initialize.c +++ b/drivers/syslog/syslog_initialize.c @@ -109,6 +109,13 @@ int syslog_initialize(enum syslog_init_e phase) #endif +#ifdef CONFIG_SYSLOG_CHARDEV + if (phase == SYSLOG_INIT_EARLY) + { + syslog_register(); + } +#endif + return ret; } diff --git a/include/nuttx/syslog/syslog.h b/include/nuttx/syslog/syslog.h index f6a4005c07..2dc54e7fe1 100644 --- a/include/nuttx/syslog/syslog.h +++ b/include/nuttx/syslog/syslog.h @@ -277,24 +277,6 @@ int syslog_flush(void); int nx_vsyslog(int priority, FAR const IPTR char *src, FAR va_list *ap); -/**************************************************************************** - * Name: syslog_register - * - * Description: - * Register a simple character driver at /dev/syslog whose write() method - * will transfer data to the SYSLOG device. This can be useful if, for - * example, you want to redirect the output of a program to the SYSLOG. - * - * NOTE that unlike other syslog output, this data is unformatted raw - * byte output with no time-stamping or any other SYSLOG features - * supported. - * - ****************************************************************************/ - -#ifdef CONFIG_SYSLOG_CHARDEV -void syslog_register(void); -#endif - #undef EXTERN #ifdef __cplusplus }