[ 
https://issues.apache.org/jira/browse/LOG4J2-2520?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17082412#comment-17082412
 ] 

ASF subversion and git services commented on LOG4J2-2520:
---------------------------------------------------------

Commit 76f4b0bbeecdfa0b42c1aa3da524e5267d45c4b0 in logging-log4j2's branch 
refs/heads/release-2.x from Ralph Goers
[ https://gitbox.apache.org/repos/asf?p=logging-log4j2.git;h=76f4b0b ]

LOG4J2-2520 - Allow servlet context path to be retrive with /


> 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
>
> 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)

Reply via email to