Reputation: 86925
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?
Upvotes: 1
Views: 3006
Reputation: 1479
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?
Upvotes: 4
Reputation: 1477
Is ${web:rootDir} a value? The placeholder is not replaced by its real value.
In the page you can red:
Information on how to use Lookups in configuration files can be found in the Property Substitution: http://logging.apache.org/log4j/2.x/manual/configuration.html#PropertySubstitution
Upvotes: 0