driver/syslog: Add microseconds after date time

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
Jiuzhu Dong 2022-03-09 16:15:50 +08:00 committed by Xiang Xiao
parent 69e69740b5
commit 840ba09b24
2 changed files with 11 additions and 1 deletions

View File

@ -137,6 +137,11 @@ config SYSLOG_TIMESTAMP_FORMAT
Formatter string for syslog timestamp printing. Formatter string for syslog timestamp printing.
Uses the standard "strftime" format specifiers. Uses the standard "strftime" format specifiers.
config SYSLOG_TIMESTAMP_FORMAT_MICROSECOND
bool "Append microseconds after seconds"
default y
depends on SYSLOG_TIMESTAMP_FORMAT = "%e/%m/%y %H:%M:%S"
config SYSLOG_TIMESTAMP_BUFFER config SYSLOG_TIMESTAMP_BUFFER
int "Formatted timestamp buffer size" int "Formatted timestamp buffer size"
default 64 default 64

View File

@ -130,11 +130,16 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap)
if (ret > 0) if (ret > 0)
{ {
#if defined(CONFIG_SYSLOG_TIMESTAMP_FORMAT_MICROSECOND)
ret = lib_sprintf(&stream.public, "[%s.%06ld] ",
date_buf, ts.tv_nsec / NSEC_PER_USEC);
#else
ret = lib_sprintf(&stream.public, "[%s] ", date_buf); ret = lib_sprintf(&stream.public, "[%s] ", date_buf);
#endif
} }
#else #else
ret = lib_sprintf(&stream.public, "[%5jd.%06ld] ", ret = lib_sprintf(&stream.public, "[%5jd.%06ld] ",
(uintmax_t)ts.tv_sec, ts.tv_nsec / 1000); (uintmax_t)ts.tv_sec, ts.tv_nsec / NSEC_PER_USEC);
#endif #endif
#endif #endif