bwaldvogel / log4j-systemd-journal-appender

Log4j appender for systemd-journal that maintains structured log data
BSD 3-Clause "New" or "Revised" License
24 stars 14 forks source link

Configurable layout and optional stack trace in journal MESSAGE #4

Closed Jajcus closed 8 years ago

Jajcus commented 8 years ago

This is my solution for #3 plus exception information.

It is not perfect and only for the 1.x version, but fixes the log4j-systemd-journal-appender limitations for me – now journalctl output is enough to replace my previous console logs. Message layout can be configured like it would be for a console output (but one would want to omit the timestamps) and exception stack trace can be included in the message too.

The layout for the appender is now optional, but log4j will complain if it is not set in the properties, which causes annoying warnings where one would expect the previous behaviour. This seems like a log4j limitation and I don't know how to fix it.

Exception stack trace inclusion is configured by a new 'appendStacktrace'. Having the stack trace in a separate journal field is still handled by 'logStacktrace'.

These changes are enough for our purposes and I am not able to commit more time to this issue, but I hope this can be still useful for upstream development.

bwaldvogel commented 8 years ago

Thanks for your contribution. Your idea is integrated. To circumvent the restirctions of log4j 1.x, I decided to introduce a new appender SystemdJournalAppenderWithLayout that requires a layout.

Allowing optional layouts was straight forward to implement for log4j 2.x on the master branch: 955996d.