You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "ASF subversion and git services (Jira)" <ji...@apache.org> on 2020/04/13 15:34:00 UTC

[jira] [Commented] (LOG4J2-2520) Improve usability of Lookup ${web:contextPath}

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

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

Commit ef5262646ae5cd82874a8fa6afb7767fec917466 in logging-log4j2's branch refs/heads/master from Ralph Goers
[ https://gitbox.apache.org/repos/asf?p=logging-log4j2.git;h=ef52626 ]

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)