You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Joaquin Diez (JIRA)" <ji...@apache.org> on 2016/09/28 10:17:20 UTC

[jira] [Created] (LOG4J2-1616) Cab´t define dynamic appName in Syslog Appender using Mdc values

Joaquin Diez created LOG4J2-1616:
------------------------------------

             Summary: Cab´t define dynamic appName in Syslog Appender using Mdc values
                 Key: LOG4J2-1616
                 URL: https://issues.apache.org/jira/browse/LOG4J2-1616
             Project: Log4j 2
          Issue Type: Bug
          Components: Appenders
    Affects Versions: 2.6.2
            Reporter: Joaquin Diez


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="integration.logtrust.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




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

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org