Log4cplus not formatting entries in the syslog and extra file

326 views Asked by At

I want to make Log4cplus to format entries in the syslog and extra file so the severity will be first, like that:

[ERROR] 2016-12-19 15:00:53.182Z [16538] int main(int, char**)  | This
is a ERROR message

Such formatting, and any other changes, using my config file, are reflected only for the console output.

In the syslog, formatting is not changing and is in this format:

Dec 19 15:19:34 e97ed7deb530 myApp: ERROR [361] myApp.cpp  - This is a ERROR message

In the extra file, formatting is not changing and is in this format:

2016-12-19 15:19:34+0000 [140675141003072] ERROR main <> - This is a ERROR message

Here is my config file:

log4cplus.appender.syslog=log4cplus::SysLogAppender
log4cplus.appender.syslog.layout=log4cplus::PatternLayout
log4cplus.appender.syslog.layout.ConversionPattern=%-5p [%T] %b %x - %m%n

log4cplus.appender.extra=log4cplus::RollingFileAppender
log4cplus.appender.extra.File=generated/obsidian-extra.log
log4cplus.appender.extra.MaxFileSize=200KB
log4cplus.appender.extra.MaxBackupIndex=5
log4cplus.appender.extra.layout=log4cplus::TTCCLayout
log4cplus.appender.extra.layout.ContextPrinting=enabled
log4cplus.appender.extra.layout.DateFormat=%F %T%z

log4cplus.appender.console=log4cplus::ConsoleAppender
log4cplus.appender.console.layout=log4cplus::PatternLayout
log4cplus.appender.console.layout.ConversionPattern=%-5p %d{%Y-%m-%d %H:%M:%S.%q}Z [%T] %M %x - %m%n

log4cplus.logger.main=ERROR, console

log4cplus.logger.main=DEBUG, default, extra, syslog
log4cplus.logger.LogTest=TRACE, extra, console, syslog

Changes in config file to formatting, only can be seen in the console output.

How can I make all the logs consistent across all the media: console, syslog and extra file?

1

There are 1 answers

0
wilx On

I think it is working as designed and your only misunderstanding the syslog output:

Dec 19 15:19:34 e97ed7deb530 myApp: ERROR [361] myApp.cpp  - This is a ERROR message

I believe that the whole of Dec 19 15:19:34 e97ed7deb530 myApp: is what syslog itself adds. The rest is according to the layout you have specified. ERROR [361] myApp.cpp - This is a ERROR message matches %-5p [%T] %b %x - %m%n.

As for the rolling file, you have specified TTCCLayout, which is specific layout. You ask for specific time stamp and you get it. The rest is thread ID, log level, etc.