diff --git a/drivers/syslog/Kconfig b/drivers/syslog/Kconfig index 976717bffb..66cfd5b533 100644 --- a/drivers/syslog/Kconfig +++ b/drivers/syslog/Kconfig @@ -273,6 +273,19 @@ menuconfig SYSLOG_FILE if SYSLOG_FILE +config SYSLOG_FILE_SEPARATE + bool "Log file separation" + default n + depends on SYSLOG_FILE + ---help--- + If enabled, every time the file logger is re-attached, a separator + will be printed in the file. + + This can be useful to easily distinguish between log entries that + belong to different log sessions (e.g. system reboot), and to + indicate that between the separated lines there may be more logs + that were lost. + config SYSLOG_FILE_ROTATIONS int "Log file rotations" default 0 diff --git a/drivers/syslog/syslog_filechannel.c b/drivers/syslog/syslog_filechannel.c index 7263ae27da..ddc27aa0fd 100644 --- a/drivers/syslog/syslog_filechannel.c +++ b/drivers/syslog/syslog_filechannel.c @@ -36,6 +36,7 @@ #include #include +#include #include "syslog.h" @@ -60,6 +61,22 @@ FAR static struct syslog_channel_s *g_syslog_file_channel; * Private Functions ****************************************************************************/ +#ifdef CONFIG_SYSLOG_FILE_SEPARATE +static void log_separate(FAR const char *log_file) +{ + struct file fp; + + if (file_open(&fp, log_file, O_WRONLY) < 0) + { + return; + } + + file_write(&fp, "\n\n", 2); + + file_close(&fp); +} +#endif + #if CONFIG_SYSLOG_FILE_ROTATIONS > 0 static void log_rotate(FAR const char *log_file) { @@ -181,6 +198,12 @@ FAR struct syslog_channel_s *syslog_file_channel(FAR const char *devpath) log_rotate(devpath); #endif + /* Separate the old log entries. */ + +#ifdef CONFIG_SYSLOG_FILE_SEPARATE + log_separate(devpath); +#endif + /* Then initialize the file interface */ g_syslog_file_channel = syslog_dev_initialize(devpath, OPEN_FLAGS,