Reset syslog color before printing messages.

This commit is contained in:
Fotis Panagiotopoulos 2022-06-04 04:26:05 +03:00 committed by Xiang Xiao
parent cd88ad3539
commit 34e7ce5817
1 changed files with 16 additions and 9 deletions

View File

@ -74,6 +74,7 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap)
#ifdef CONFIG_SYSLOG_TIMESTAMP
struct timespec ts;
#if defined(CONFIG_SYSLOG_TIMESTAMP_FORMATTED)
int d_ret;
struct tm tm;
char date_buf[CONFIG_SYSLOG_TIMESTAMP_BUFFER];
#endif
@ -124,22 +125,28 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap)
#endif
}
#if defined(CONFIG_SYSLOG_TIMESTAMP_FORMATTED)
ret = strftime(date_buf, CONFIG_SYSLOG_TIMESTAMP_BUFFER,
CONFIG_SYSLOG_TIMESTAMP_FORMAT, &tm);
#if defined(CONFIG_SYSLOG_COLOR_OUTPUT)
/* Reset the terminal style. */
if (ret > 0)
ret = lib_sprintf(&stream.public, "\e[0m");
#endif
#if defined(CONFIG_SYSLOG_TIMESTAMP_FORMATTED)
d_ret = strftime(date_buf, CONFIG_SYSLOG_TIMESTAMP_BUFFER,
CONFIG_SYSLOG_TIMESTAMP_FORMAT, &tm);
if (d_ret > 0)
{
#if defined(CONFIG_SYSLOG_TIMESTAMP_FORMAT_MICROSECOND)
ret = lib_sprintf(&stream.public, "[%s.%06ld] ",
date_buf, ts.tv_nsec / NSEC_PER_USEC);
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
ret = lib_sprintf(&stream.public, "[%5jd.%06ld] ",
(uintmax_t)ts.tv_sec, ts.tv_nsec / NSEC_PER_USEC);
ret += lib_sprintf(&stream.public, "[%5jd.%06ld] ",
(uintmax_t)ts.tv_sec, ts.tv_nsec / NSEC_PER_USEC);
#endif
#endif