Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1616

Can´t define dynamic appName in Syslog Appender using Mdc values

    XMLWordPrintableJSON

Details

    • Important

    Description

      I need to define the value of the appName based on the user logged in the system.

      Wheh the user Logsin I add in the ThreadContext the following

      ThreadContext.put("domain", "mydomain");

      This is the log4j2.xml content

      <?xml version="1.0" encoding="UTF-8"?>
      <Configuration status="WARN">
      
          <Properties>
              <Property name="format1">%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - $${ctx:user}|$${ctx:domain}|$${ctx:cid}|%msg|%throwable{full,separator( )}%n</Property>
              <Property name="format_noex">%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - $${ctx:user}|$${ctx:domain}|$${ctx:cid}|%msg%n</Property>
          </Properties>
      
      
          <Appenders>
              <Console name="Console" target="SYSTEM_OUT">
                  <PatternLayout pattern="${format1}"/>
              </Console>
              <Syslog name="syslog_unsecure_out"
                      host="my.syslog.server.com"
                      port="1514"
                      protocol="TCP"
                      includeMDC="true"
                      mdcId="mdc"
                      newLine="true"
                      facility="LOCAL0"
                      messageId="out"
                      format="RFC5424"
                      appName="test.keep.free.$${ctx:domain}">
                  <LoggerFields>
                      <KeyValuePair key="ex" value="%throwable{full,separator( )}"/>
                  </LoggerFields>
              </Syslog>
      
          </Appenders>
          <Loggers>
              <Root level="info">
                  <AppenderRef ref="Console"/>
                  <AppenderRef ref="syslog_unsecure_out"/>
              </Root>
          </Loggers>
      </Configuration>
      

      But the output in my syslog server is

      2016-09-28 10:15:38.166 macbook-pro-de-joaquin-2.local=2.139.166.115 local0.info test.keep.free.${ctx:domain} - out [mdc@18060 cid="000013FFF" domain="dominio" ex="" user="usuario"] test info mensaje.....
      

      So, as you can see the appName generated is test.keep.free.${ctx:domain}

      not the expected test.keep.free.mydomain

      Attachments

        Activity

          People

            Unassigned Unassigned
            joaquindiez Joaquin Diez
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: