Issue
I want to configure log4j2
to lookup the logging path dynamically from web startup (tomcat).
From the docs (http://logging.apache.org/log4j/2.x/manual/lookups.html) there is a web:
lookup with different parameter possibilities.
At first I'm trying the provided example:
<Appenders>
<File name="ApplicationLog" fileName="${web:rootDir}/app.log"/>
</Appenders>
Result: ERROR Unable to create file ${web:rootDir}/app.log java.io.IOException
I also tried the other buildin properties like servletContextName
and contextPath
with the same error message.
So I'm probably still missing something important. But what?
Solution
Add log4j-web JAR
Your usual log4j-core
JAR file on its own is not enough.
There is an additional component called log4j-web
.
For automatic replacement of the ${web:...}
placeholders in your logging configuration, you need the additional log4j-web
JAR file. If you don't have this log4j-web JAR file, then Log4j2 itself will still work, but it will not replace these placeholders with anything. So for example ${web:rootDir}
will just end up as the literal text ${web:rootDir}
.
Perhaps you are missing that dependency in your project?
Answered By - JeroenHoek