Skip to content

Commit

Permalink
syslog: add option to prefix process name
Browse files Browse the repository at this point in the history
  • Loading branch information
protobits authored and acassis committed Mar 11, 2021
1 parent d87274c commit cf8521e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
20 changes: 13 additions & 7 deletions drivers/syslog/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,20 @@ config SYSLOG_TIMESTAMP_BUFFER
---help---
Buffer size to store syslog formatted timestamps.

config SYSLOG_COLOR_OUTPUT
bool "Colored syslog output"
default n
---help---
Enables colored output in syslog, according to message priority.

config SYSLOG_PRIORITY
bool "Prepend priority to syslog message"
default n
---help---
Prepend log priority (severity) to syslog message.

config SYSLOG_PROCESS_NAME
bool "Prepend process name to syslog message"
default n
---help---
Prepend Process name to syslog message.

config SYSLOG_PROCESSID
bool "Prepend Process ID to syslog message"
bool "Prepend process ID to syslog message"
default n
---help---
Prepend Process ID to syslog message.
Expand All @@ -173,6 +173,12 @@ config SYSLOG_PREFIX_STRING
---help---
The prefix string to be prepend.

config SYSLOG_COLOR_OUTPUT
bool "Colored syslog output"
default n
---help---
Enables colored output in syslog, according to message priority.

choice
prompt "System log device"
default SYSLOG_CONSOLE if !ARCH_LOWPUTC
Expand Down
18 changes: 14 additions & 4 deletions drivers/syslog/vsyslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap)
{
struct lib_syslogstream_s stream;
int ret;
#if CONFIG_TASK_NAME_SIZE > 0 && defined(CONFIG_SYSLOG_PROCESS_NAME)
struct tcb_s *tcb;
#endif
#if defined(CONFIG_SYSLOG_TIMESTAMP_FORMATTED)
time_t time;
struct tm tm;
Expand Down Expand Up @@ -131,7 +134,7 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap)
}

#if defined(CONFIG_SYSLOG_TIMESTAMP)
/* Pre-pend the message with the current time, if available */
/* Prepend the message with the current time, if available */

#if defined(CONFIG_SYSLOG_TIMESTAMP_FORMATTED)
time = ts.tv_sec;
Expand All @@ -157,7 +160,7 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap)
#endif

#if defined(CONFIG_SYSLOG_PROCESSID)
/* Pre-pend the Process ID */
/* Prepend the Process ID */

ret += lib_sprintf(&stream.public, "[%2d] ", (int)getpid());
#endif
Expand Down Expand Up @@ -201,17 +204,24 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap)
#endif

#if defined(CONFIG_SYSLOG_PRIORITY)
/* Pre-pend the message priority. */
/* Prepend the message priority. */

ret += lib_sprintf(&stream.public, "[%6s] ", g_priority_str[priority]);
#endif

#if defined(CONFIG_SYSLOG_PREFIX)
/* Pre-pend the prefix, if available */
/* Prepend the prefix, if available */

ret += lib_sprintf(&stream.public, "%s", CONFIG_SYSLOG_PREFIX_STRING);
#endif

#if CONFIG_TASK_NAME_SIZE > 0 && defined(CONFIG_SYSLOG_PROCESS_NAME)
/* Prepend the process name */

tcb = nxsched_get_tcb(getpid());
ret += lib_sprintf(&stream.public, "%s: ", tcb->name);
#endif

/* Generate the output */

ret += lib_vsprintf(&stream.public, fmt, *ap);
Expand Down

0 comments on commit cf8521e

Please sign in to comment.