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?
For automatic replacement of the ${web:...}
placeholders in your logging configuration, you need the log4j-web
jar as well as log4j-core
. Without the former Log4j2 will work, but it won't replace these placeholders.
Perhaps you are missing that dependency in your project?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.