Priya Ahuja created LOG4J2-1460:
-----------------------------------

             Summary: Multiple structured data elements in syslog while using 
combination of StructuredDataMessage and MDC
                 Key: LOG4J2-1460
                 URL: https://issues.apache.org/jira/browse/LOG4J2-1460
             Project: Log4j 2
          Issue Type: Bug
    Affects Versions: 2.6.1
            Reporter: Priya Ahuja


Hi,

I am using Log4j 2.6.1 and while using StructuredDataMessage in combination 
with MDC, I am noticing duplicate structured data fields if the mdcId 
mismatches. If the mdcId is the same in log4j2.xml and StructuredDataMessage 
then the log is dropped all together. 

Expected behavior:
If mdcId in log4j2.xml and "id" parameter of StructuredDataMessage matches then 
only 1 structured data element must be created that combines the two 
configuration.

Output:
- When keys are different (Notice two structured data fields)
<182>1 2016-07-12T00:22:35.451Z nsx-manager NSX - - [nsx1@6876 
comp="nsx-manager"][nsx@6876] One delta state sync provider is registered 

-When keys are the same:
No log is seen

Log4j2.xml Syslog appender:
        <Syslog name="RFC5424" format="RFC5424"
                host="localhost"
                port="514"
                protocol="UDP"
                appName="NSX"
                facility="LOCAL6"
                enterpriseNumber="6876" newLine="true"
                messageId="-" id="-" includeMDC="true" mdcId="nsx1">
            <ThresholdFilter level="INFO"/>
        </Syslog>

Facade Code:
private Message format(String msg) {
       return new StructuredDataMessage("nsx", msg, "-");
}
    public void log(Level level, String msg) {
        if (log4jLogger.isEnabled(level)) {
            ThreadContext.put("comp", "nsx-manager");
            log4jLogger.logMessage(FQCN, level, null, this.format(msg), null);
            ThreadContext.clearAll();
         }
    }




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to