Load log4j2.xml file outside project with enviroment variable
Asked Answered
M

1

1

I am developing a java web-app (v3.0) for a TomCat 7.0 server and I am having troubles loading the log4j2.xml file.

I have defined the log4j2.xml file outside my project and defined the path for the file in my web.xml file.

If i hardcode the path my log4j2.xml file loads as it should.

<context-param>
    <param-name>log4jConfiguration</param-name>
    <param-value>file:///C:/my/path/log4j2.xml</param-value>
</context-param>    

On the other hand I want to use an enviroment variable to define the path.

<context-param>
    <param-name>log4jConfiguration</param-name>
    <param-value>file:///${ENVIROMENT_VARIABLE}/log4j2.xml</param-value>
</context-param>

When I start TomCat I have this error:

ERROR SatusLogger Unable to access file:///$%7BENVIROMENT_VARIABLE%7D/log4j2.xml

It looks like it isn't 'translating' the variable.

Any help will be very aprecciated.

PD: Sorry for my english.

Magee answered 12/5, 2016 at 14:27 Comment(0)
H
3

Log4j interpolates the value it finds for log4jConfiguration in web.xml. However, you have to use standard Log4j Lookup syntax. To get an environment variable you would specify:

<context-param>
    <param-name>log4jConfiguration</param-name>
    <param-value>file:///${env:ENVIROMENT_VARIABLE}/log4j2.xml</param-value>
</context-param>
Hammering answered 12/5, 2016 at 18:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.