[
https://issues.apache.org/jira/browse/LOG4J2-2520?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Ralph Goers resolved LOG4J2-2520.
---------------------------------
Fix Version/s: 2.13.2
Resolution: Fixed
A new contextPathName key has been added to the Lookup. Please verify and close.
> Improve usability of Lookup ${web:contextPath}
> ----------------------------------------------
>
> Key: LOG4J2-2520
> URL: https://issues.apache.org/jira/browse/LOG4J2-2520
> Project: Log4j 2
> Issue Type: Improvement
> Components: Lookups
> Affects Versions: 2.11.1
> Environment: Tested in Tomcat 8.5 on Windows 7
> Reporter: Christoph Wagner
> Priority: Major
> Fix For: 2.13.2
>
>
> The contextPath lookup value is used without any cleanup in WebLookup.java
> {code:java}
> if ("contextPath".equals(key)) {
> return ctx.getContextPath();
> }
> {code}
> It's not possible to use this value as part of a file name, because the
> contextPath starts with a / character which forces a new sub-directory.
> Imagine a web-app name cde and the following configuration:
> {code:java}
> <Property name="BASE_NAME">awp-${web:contextPath}.log</Property>
> {code}
> Expected is a log file called awp-cde.log but the result is awp/cde.log. This
> is especially a problem for the ROOT webapp which results in awp/.log
> The proposed solution is to always remove the leading slash from the
> contextPath as it can be added in the property definition manually:
> {code:java}
> if ("contextPath".equals(key)) {
> return ctx.getContextPath().length () > 1 ?
> ctx.getContextPath().substring(1) : "";
> }
> {code}
> Another change could be to return a hard-coded ROOT in case the contextPath
> returns the empty placeholder for the ROOT webapp:
> {code:java}
> if ("contextPath".equals(key)) {
> return ctx.getContextPath().length () > 1 ?
> ctx.getContextPath().substring(1) : "ROOT";
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)