diff --git a/drivers/syslog/Kconfig b/drivers/syslog/Kconfig index 87e4fe2476..b502261695 100644 --- a/drivers/syslog/Kconfig +++ b/drivers/syslog/Kconfig @@ -59,6 +59,13 @@ config RAMLOG_NPOLLWAITERS ---help--- The maximum number of threads that may be waiting on the poll method. +config RAMLOG_OVERWRITE + bool "RAMLOG overwrite circular buffer" + default n + ---help--- + Enable overwrite of circular buffer. If RAMLOG buffer overflows, + overwrite it from the top of buffer and always keep the latest log. + endif config DRIVER_NOTE diff --git a/drivers/syslog/ramlog.c b/drivers/syslog/ramlog.c index a6ff6cc92b..0675ede5ef 100644 --- a/drivers/syslog/ramlog.c +++ b/drivers/syslog/ramlog.c @@ -227,10 +227,20 @@ static ssize_t ramlog_addchar(FAR struct ramlog_dev_s *priv, char ch) if (nexthead == priv->rl_tail) { +#ifdef CONFIG_RAMLOG_OVERWRITE + /* Yes... Overwrite with the latest log in the circular buffer */ + + priv->rl_tail += 1; + if (priv->rl_tail >= priv->rl_bufsize) + { + priv->rl_tail = 0; + } +#else /* Yes... Return an indication that nothing was saved in the buffer. */ leave_critical_section(flags); return -EBUSY; +#endif } /* No... copy the byte and re-enable interrupts */