mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 03:05:40 +08:00
syslog: Added separator in file logs.
This commit is contained in:
committed by
Xiang Xiao
parent
b3e8535ad6
commit
b73dc0f166
@@ -273,6 +273,19 @@ menuconfig SYSLOG_FILE
|
|||||||
|
|
||||||
if 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
|
config SYSLOG_FILE_ROTATIONS
|
||||||
int "Log file rotations"
|
int "Log file rotations"
|
||||||
default 0
|
default 0
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
#include <nuttx/syslog/syslog.h>
|
#include <nuttx/syslog/syslog.h>
|
||||||
#include <nuttx/kmalloc.h>
|
#include <nuttx/kmalloc.h>
|
||||||
|
#include <nuttx/fs/fs.h>
|
||||||
|
|
||||||
#include "syslog.h"
|
#include "syslog.h"
|
||||||
|
|
||||||
@@ -60,6 +61,22 @@ FAR static struct syslog_channel_s *g_syslog_file_channel;
|
|||||||
* Private Functions
|
* 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
|
#if CONFIG_SYSLOG_FILE_ROTATIONS > 0
|
||||||
static void log_rotate(FAR const char *log_file)
|
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);
|
log_rotate(devpath);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Separate the old log entries. */
|
||||||
|
|
||||||
|
#ifdef CONFIG_SYSLOG_FILE_SEPARATE
|
||||||
|
log_separate(devpath);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Then initialize the file interface */
|
/* Then initialize the file interface */
|
||||||
|
|
||||||
g_syslog_file_channel = syslog_dev_initialize(devpath, OPEN_FLAGS,
|
g_syslog_file_channel = syslog_dev_initialize(devpath, OPEN_FLAGS,
|
||||||
|
|||||||
Reference in New Issue
Block a user