You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "André Pinto (Jira)" <ji...@apache.org> on 2020/03/04 16:04:00 UTC

[jira] [Commented] (LOG4J2-2799) Thread context map property resolution doesn't work for Appender's filename

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

André Pinto commented on LOG4J2-2799:
-------------------------------------

Thanks for your reply.

Can you please add that information to the documentation so people do not try to use thread context map properties even when statically defined in the xml (meaning they would never change after the creation of the RollingFileAppender)?

Also, is there any way to reuse Appender configuration across Loggers in XML or do I have to move to purely programmatic configuration for this?

> 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)