[
https://issues.apache.org/jira/browse/LOG4J2-969?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14347694#comment-14347694
]
Paul D Johe commented on LOG4J2-969:
------------------------------------
My use case is as follows: I want to add MDC (thread context) data to the old
BSD formats. So I was going to create my own BsdSyslogLayout class that has a
pattern (like the PatternLayout). The way the code is now, the SyslogAppender
layout parameter is not extendable at all. (The new log4j2 plugin system is
brilliant by the way!) Furthermore, both SyslogLayout and PatternLayout classes
are final...
Ideally I think the following should be done:
1. Remove final classifier from SyslogLayout and PatternLayout classes - it
takes away from the new log4j2 plugin extendability
2. Add a new 'layout' PluginElement to SyslogAppender
- if layout is null (not used), issue a warning that 'format' is depreciated
but use existing functionality as the code stands today (the code changes
performed are backwards compatible)
- if both layout and format are given, log an error that both layout and
format cannot be used at the same time
3. Rename SyslogLayout to BsdSyslogLayout (clearer name), change the class to
extend the PatternLayout so that the pattern can be used for getting the
'message' part of the syslog message (so that it is possible to still get
thread context data in the BSD syslog messages)
This would solve
http://stackoverflow.com/questions/17947611/log4j2-syslog-appender-and-patternlayout
to the following:
{code}
<Syslog name="syslog" host="localhost" port="514" protocol="UDP">
<BsdSyslogLayout charset="ISO-8859-1" pattern="%Xcategory[%logger{36}] -
%msg"/>
</Syslog>
{code}
RFC5424 code will look like this:
{code}
<Syslog name="syslog" host="localhost" port="514" protocol="UDP">
<Rfc5424Layout appName="MyApp" includeMDC="true"
facility="LOCAL0" enterpriseNumber="18060" newLine="true"
messageId="Audit" id="App"/>
</Syslog>
{code}
And it is possible to write a new custom layout:
{code}
<Syslog name="syslog" host="localhost" port="514" protocol="UDP">
<InfoLoggerLevelAsNoticeSeverityLayout ... />
</Syslog>
{code}
I would be happy to provide a patch and unit tests...
> Refactor syslogappender so that Layout is an PluginElement
> ----------------------------------------------------------
>
> Key: LOG4J2-969
> URL: https://issues.apache.org/jira/browse/LOG4J2-969
> Project: Log4j 2
> Issue Type: Improvement
> Components: Appenders, Layouts
> Affects Versions: 2.2
> Reporter: Paul D Johe
> Labels: syslog, syslogappender
>
> There are quite a lot of attributes to the syslogappender that could have
> been simply included as:
> {code}
> @PluginElement("layout") Layout<? extends Serializable> layout,
> {code}
> This is much more flexible (for example, extension of existing syslog
> layouts) and the field 'format' becomes superfluous, as it is implied by the
> layout chosen (normally SyslogLayout or Rfc5424Layout will be chosen).
> Furthermore, it becomes much clearer which attributes are for the RFC5424
> format and which are for the BSD format.
> Or at least add the possibility for a Layout element, which if does not exist
> will use the existing code.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]