Add optional timestamp to syslog output. From pn_bouteville@yahoo.fr

This commit is contained in:
Gregory Nutt 2014-11-01 09:17:34 -06:00
parent a86d86e866
commit e6c2a36bbe
3 changed files with 63 additions and 12 deletions

View File

@ -70,7 +70,7 @@
*******************************************************************************************************************************/
/* ETM Register Base Address ***************************************************************************************************/
#define ETM_BASE
#define ETM_BASE (0xe0041000ul)
/* ETM Register Offsets ********************************************************************************************************/

View File

@ -75,6 +75,12 @@ config SYSLOG
if SYSLOG
config SYSLOG_TIMESTAMP
bool "Prepend timestamp to syslog message"
default y
---help---
Prepend timestamp to syslog message.
config SYSLOG_CHAR
bool "System log character device support"
default y

View File

@ -42,6 +42,7 @@
#include <stdio.h>
#include <syslog.h>
#include <nuttx/clock.h>
#include <nuttx/streams.h>
#include "syslog/syslog.h"
@ -94,41 +95,85 @@
static inline int vsyslog_internal(FAR const char *fmt, va_list ap)
{
#if defined(CONFIG_SYSLOG)
struct lib_outstream_s stream;
#elif CONFIG_NFILE_DESCRIPTORS > 0
struct lib_rawoutstream_s stream;
#elif defined(CONFIG_ARCH_LOWPUTC)
struct lib_outstream_s stream;
#endif
#if defined(CONFIG_SYSLOG_TIMESTAMP)
struct timespec ts;
int ret;
/* Get the current time */
ret = clock_systimespec(&ts);
#endif
#if defined(CONFIG_SYSLOG)
/* Wrap the low-level output in a stream object and let lib_vsprintf
* do the work.
*/
lib_syslogstream((FAR struct lib_outstream_s *)&stream);
#if defined(CONFIG_SYSLOG_TIMESTAMP)
/* Pre-pend the message with the current time */
if (ret == OK)
{
(void)lib_sprintf((FAR struct lib_outstream_s *)&stream,
"[%6d.%06d]",
ts.tv_sec, ts.tv_nsec/1000);
}
#endif
return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap);
#elif CONFIG_NFILE_DESCRIPTORS > 0
struct lib_rawoutstream_s rawoutstream;
/* Wrap the stdout in a stream object and let lib_vsprintf
* do the work.
*/
lib_rawoutstream(&rawoutstream, 1);
return lib_vsprintf(&rawoutstream.public, fmt, ap);
lib_rawoutstream(&stream, 1);
#if defined(CONFIG_SYSLOG_TIMESTAMP)
/* Pre-pend the message with the current time */
if (ret == OK)
{
(void)lib_sprintf((FAR struct lib_outstream_s *)&stream,
"[%6d.%06d]",
ts.tv_sec, ts.tv_nsec/1000);
}
#endif
return lib_vsprintf(&stream.public, fmt, ap);
#elif defined(CONFIG_ARCH_LOWPUTC)
struct lib_outstream_s stream;
/* Wrap the low-level output in a stream object and let lib_vsprintf
* do the work.
*/
lib_lowoutstream((FAR struct lib_outstream_s *)&stream);
#if defined(CONFIG_SYSLOG_TIMESTAMP)
/* Pre-pend the message with the current time */
if (ret == OK)
{
(void)lib_sprintf((FAR struct lib_outstream_s *)&stream,
"[%6d.%06d]",
ts.tv_sec, ts.tv_nsec/1000);
}
#endif
return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap);
#else
#else /* CONFIG_SYSLOG */
return 0;
#endif
#endif /* CONFIG_SYSLOG */
}
/****************************************************************************