[ 
https://issues.apache.org/jira/browse/LOG4J2-2636?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16869658#comment-16869658
 ] 

Ralph Goers edited comment on LOG4J2-2636 at 6/21/19 4:40 PM:
--------------------------------------------------------------

The suggested patch is wrong. The id field is the default structured data id 
for all structured data elements. The mdcId field is the id value for the mdc 
structured data element only. Normally these would be the same but they don't 
have to be. So the id value should be the default for the mdcId.

the code really should be
{code:java}
this.mdcId = mdcId != null ? mdcId : id == null ? DEFAULT_MDCID : id;
this.mdcSdId = new StructuredDataId(this.mdcId, enterpriseNumber, null, 
null);{code}
 


was (Author: ralph.go...@dslextreme.com):
The suggested patch is wrong. The id field is the default structured data id 
for all structured data elements. The mdcId field is the id value for the mdc 
structured data element only. Normally these would be the same but they don't 
have to be. So the id value is the default for the mdcId, which is exactly what 
is in the code now.

> No default value for mdcId in SyslogAppender
> --------------------------------------------
>
>                 Key: LOG4J2-2636
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2636
>             Project: Log4j 2
>          Issue Type: Bug
>    Affects Versions: 2.11.2
>            Reporter: Filipp Gunbin
>            Priority: Major
>
> 1) Main issue
> When Rfc5424Layout is created from configuration, it seems to receive default 
> value:
> {code:java}
> @PluginAttribute(value = "mdcId", defaultString = DEFAULT_MDCID) final String 
> mdcId,{code}
> But SyslogAppender has it with no default:
> {code:java}
> @PluginBuilderAttribute("mdcId")
> private String mdcId;{code}
> It is used in SyslogAppender.build() to create Rfc5424Layout.  So, if I don't 
> specify "mdcId" attribute in <Syslog>" config element, I get this exception:
> {quote}ERROR StatusLogger Could not create plugin of type class 
> org.apache.logging.log4j.core.appender.SyslogAppender for element Syslog: 
> java.lang.IllegalArgumentException: No structured id name was supplied 
> java.lang.IllegalArgumentException: No structured id name was supplied at 
> org.apache.logging.log4j.message.StructuredDataId.<init>(StructuredDataId.java:146)
>  at 
> org.apache.logging.log4j.message.StructuredDataId.<init>(StructuredDataId.java:130)
>  at 
> org.apache.logging.log4j.core.layout.Rfc5424Layout.<init>(Rfc5424Layout.java:142)
>  at 
> org.apache.logging.log4j.core.layout.Rfc5424Layout.createLayout(Rfc5424Layout.java:672)
>  at 
> org.apache.logging.log4j.core.appender.SyslogAppender$Builder.build(SyslogAppender.java:117)
>  at 
> org.apache.logging.log4j.core.appender.SyslogAppender$Builder.build(SyslogAppender.java:50)
> {quote}
> 2) Documentation doesn't mention mdcId of SyslogAppender at all: 
> [https://logging.apache.org/log4j/2.x/manual/appenders.html#SyslogAppender]
> If I build site locally with "mvn site" in 2.11.2, it's not there either.
> 3) Commit ce1183629fe89625a77872c7153853e7774502a6 
> (https://issues.apache.org/jira/browse/LOG4J2-922) which introduces default 
> value for mdcId in Rfc5424Layout has this code:
> {code:java}
> this.mdcId = id == null ? DEFAULT_MDCID : id;         
> this.mdcSdId = new StructuredDataId(mdcId, enterpriseNumber, null, 
> null);{code}
> While "this.mdcId" is set in first line, the argument (not class member) 
> mdcId is used in the second line.  Maybe argument mdcId should be used in the 
> first line instead of "id"?  Maybe this.mdcId should be used in the second 
> line instead of argument mdcId? I'm not familiar with the code enough to tell 
> for sure, it just feels suspicious to me.
> Thanks.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to