I started thinking about this and realized I have given you an incorrect answer.

The file appender is initialized when the configuration is processed and is not 
reevaluated for every event.  Thus giving it a variable with 2 '$' characters 
doesn't make sense.  Likewise, when the configuration is processed it is likely 
that your ThreadContext.put() call hasn't taken place yet and so you are 
getting the variable expression as the value since it hasn't been defined.  If 
you really want an appender that can write to a different file based on a 
ThreadContext value then you would need to use the RoutingAppender.

Ralph


On Dec 21, 2012, at 4:23 PM, Michael Minella wrote:

> 
> I'm looking at the log4j 2 's thread specific features and had a question. In 
> my code I set an id as follows: 
> 
> 
> 
> ThreadContext.put( "id" , "Main" ); 
> 
> 
> and attempt to reference it in my configuration file as shown below: 
> 
> 
> 
> < File name = "File" fileName = "/tmp/myLog.log" > 
> < PatternLayout pattern = "%X{id} %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} 
> - %msg ${ctx:id} %n" /> 
> </ File > 
> 
> 
> If I use the lookup in the pattern layout to test it, it works fine. However, 
> if I move that lookup to the fileName attribute in the line above, the 
> replacement doesn't occur (my file ends up being named /tmp/${ctx.id}.log for 
> example). Is that a limitation of that lookup or am I missing something? Any 
> insight that can be provided is appreciated. Thanks in advance! 
> 
> Thanks, 
> Michael T Minella 


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org

Reply via email to