Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2520

Improve usability of Lookup ${web:contextPath}

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.11.1
    • Fix Version/s: None
    • Component/s: Lookups
    • Labels:
      None
    • Environment:

      Tested in Tomcat 8.5 on Windows 7

      Description

      The contextPath lookup value is used without any cleanup in WebLookup.java

      if ("contextPath".equals(key)) {
          return ctx.getContextPath();
      }
      

      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:

      <Property name="BASE_NAME">awp-${web:contextPath}.log</Property>
      

      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:

      if ("contextPath".equals(key)) {
          return ctx.getContextPath().length () > 1 ? ctx.getContextPath().substring(1) : "";
      }
      

      Another change could be to return a hard-coded ROOT in case the contextPath returns the empty placeholder for the ROOT webapp:

      if ("contextPath".equals(key)) {
          return ctx.getContextPath().length () > 1 ? ctx.getContextPath().substring(1) : "ROOT";
      }
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              campus Christoph Wagner
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: