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

Ralph Goers commented on LOG4J2-671:
------------------------------------

Normally, all variables with a single '$' are resolved when the configuration 
is read. However, the properties have to be resolved using only the hard-wired 
lookups, which for some reason does not include the date lookup, as the 
properties need to be read to create the "real" Interpolator. If we add the 
date lookup to the hard-wired list it would probably resolve this issue but 
might break existing configurations.

> Property using ${date:} is evaluated multiple times across appenders
> --------------------------------------------------------------------
>
>                 Key: LOG4J2-671
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-671
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Configurators
>    Affects Versions: 2.0-rc1
>         Environment: OS: Ubuntu 12.04
>            Reporter: Robert Veitch
>
> At the top of my log4j2.xml config I have the following properties:
> {code}
> <Properties>
>     <Property name="log_date">${date:yyyy-MM-dd'T'HHmmssSSS></Property>
>     <Property name="log_path">log/${log_date}</Property>
> </Properties>
> {code}
> I would like to use the "log_path" property as the root log directory for all 
> my appenders. By including a timestamp in "log_path" I can distinguish 
> between multiple runs of my application. My appenders refer to "log_path" in 
> the following way:
> {code}
> <RollingRandomAccessFile name="ApplicationLog" append="true"
>         fileName="${log_path}/application.log"
>         
> filePattern="${log_path}/application.log-$${date:yyyy-MM-dd'T'HHmmssSSS}.gz">
> ..snip..
> </RollingRandomAccessFile>
> {code}
> I have several such appenders, and I'd like them to all refer to the same 
> "log_path" value. Unfortunately, it seems that the property gets re-evaluated 
> for each appender, so I end up with multiple log directories on a given run 
> of my application. Below is an example:
> ls -al log/
> total 20
> drwxr-xr-x 5 rveitch rveitch 4096 Jun 16 14:12 .
> drwxrwxr-x 6 rveitch rveitch 4096 Jun 16 13:18 ..
> drwxrwxr-x 2 rveitch rveitch 4096 Jun 16 14:12 2014-06-16T141225420
> drwxrwxr-x 2 rveitch rveitch 4096 Jun 16 14:12 2014-06-16T141225462
> drwxrwxr-x 2 rveitch rveitch 4096 Jun 16 14:12 2014-06-16T141225501
> Is there anyway to evaluate a property once, such that the value is frozen 
> for re-use across appenders? Is there an alternative approach to generate a 
> timestamp which I can use as a part of a common log directory path?



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