diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-11-01 09:17:34 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-11-01 09:17:34 -0600 |
commit | 3a82d6e056e447bc69b16db1694387b7931b30bd (patch) | |
tree | 75bee8d81ee89fa7f8f33bc27aa2d6669b5a7baf /nuttx/libc | |
parent | 1066988276d7a680a21f755943778e9bb80bc3cd (diff) | |
download | px4-nuttx-3a82d6e056e447bc69b16db1694387b7931b30bd.tar.gz px4-nuttx-3a82d6e056e447bc69b16db1694387b7931b30bd.tar.bz2 px4-nuttx-3a82d6e056e447bc69b16db1694387b7931b30bd.zip |
Add optional timestamp to syslog output. From pn_bouteville@yahoo.fr
Diffstat (limited to 'nuttx/libc')
-rw-r--r-- | nuttx/libc/syslog/lib_syslog.c | 65 |
1 files changed, 55 insertions, 10 deletions
diff --git a/nuttx/libc/syslog/lib_syslog.c b/nuttx/libc/syslog/lib_syslog.c index 63441fd9e..70e8e13de 100644 --- a/nuttx/libc/syslog/lib_syslog.c +++ b/nuttx/libc/syslog/lib_syslog.c @@ -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); - return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap); -#elif CONFIG_NFILE_DESCRIPTORS > 0 +#if defined(CONFIG_SYSLOG_TIMESTAMP) + /* Pre-pend the message with the current time */ - struct lib_rawoutstream_s rawoutstream; + 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 /* 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); -#elif defined(CONFIG_ARCH_LOWPUTC) +#if defined(CONFIG_SYSLOG_TIMESTAMP) + /* Pre-pend the message with the current time */ - struct lib_outstream_s stream; + 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) /* 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 */ } /**************************************************************************** |