syslog: Added separator in file logs.

This commit is contained in:
Fotis Panagiotopoulos 2021-06-08 13:17:31 +03:00 committed by Xiang Xiao
parent b3e8535ad6
commit b73dc0f166
2 changed files with 36 additions and 0 deletions

View File

@ -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

View File

@ -36,6 +36,7 @@
#include <nuttx/syslog/syslog.h>
#include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h>
#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,