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

Ralph Goers commented on LOG4J2-2799:
-------------------------------------

I don't understand what you mean by "reuse Appender configuration across 
Loggers". Your "main-server" Logger and "main-serverNotify" Logger are both 
referencing the same Appender, so they are reusing the same appender 
configuration.

> Thread context map property resolution doesn't work for Appender's filename
> ---------------------------------------------------------------------------
>
>                 Key: LOG4J2-2799
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2799
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Configuration
>    Affects Versions: 2.13.1
>         Environment: * log4j 2.13.1
>  * macOS 10.13.6
>  * Java 11.0.2
>            Reporter: André Pinto
>            Priority: Major
>
> The documentation says:
>  
> {noformat}
> A LoggerConfig (including the root LoggerConfig) can be configured with 
> properties that will be added to the properties copied from the 
> ThreadContextMap. These properties can be referenced from Appenders, Filters, 
> Layouts, etc just as if they were part of the ThreadContext Map.{noformat}
> but if I set a property "*prop*" for a logger and try to use it for in the 
> appender filename by referencing "*${ctx:prop}*" the variable is not replaced.
> This functionality would be useful for reusing appender configuration by 
> loggers that need different filenames.
> Example of configuration:
>  
> {code:java}
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration status="warn" name="MyApp" packages="">
>     <Properties>
>         <Property name="LOG_DIR">logs</Property>
>     </Properties>
>     <Appenders>
>         <Console name="Console" target="SYSTEM_OUT"/>
>         <RollingFile
>                 name="rollingFile"
>                 fileName="${LOG_DIR}/${ctx:filename-prefix}.log-active"
>                 filePattern="${LOG_DIR}/${ctx:filename-prefix}.%d{dd-MMM}.log"
>                 ignoreExceptions="false">
>             <PatternLayout>
>                 <Pattern>%m</Pattern>
>             </PatternLayout>
>             <Policies>
>                 <OnStartupTriggeringPolicy />
>                 <SizeBasedTriggeringPolicy size="10 MB" />
>                 <TimeBasedTriggeringPolicy />
>             </Policies>
>             <DefaultRolloverStrategy max="5" />
>         </RollingFile>
>         <Async name="Async">
>             <AppenderRef ref="rollingFile"/>
>         </Async>
>     </Appenders>
>     <Loggers>
>         <Root level="OFF">
>             <AppenderRef ref="Console" />
>         </Root>
>         <Logger name="main-server" level="INFO" additivity="false">
>             <Property name="filename-prefix">server</Property>
>             <AppenderRef ref="Async"/>
>         </Logger>
>         <Logger name="main-serverNotify" level="INFO" additivity="false">
>             <Property name="filename-prefix">serverNotify</Property>
>             <AppenderRef ref="Async"/>
>         </Logger>
>     </Loggers>
> </Configuration>
> {code}
> This seems to be an old common problem of thread context map resolution as 
> reported in [https://stackoverflow.com/q/49953883/43046] in April 2018.
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to