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

Extend %c conversion pattern - separately control the number of characters in each class component and the number of elements that are fully specified

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.11.0
    • None
    • Pattern Converters
    • None
    • Testing was on Windows 7 with JDK 8. Production will be on Linux with JDK 8.

    Description

      I want to be able to achieve something with the %c conversion pattern that isn't possible at the moment.

      Given a logger name of "org.apache.solr.core.SolrCore.Request", I want the log to contain "o.a.s.c.SolrCore.Request" – single character abbreviations for all components except the last two.

      Solr's log4j configuration currently includes a conversion pattern of %c{1.}.This changes the logger name I mentioned above to "o.a.s.c.S.Request". With only one class name component fully specified, it's difficult to find the logger – particularly in this case, because the logger name is special and doesn't refer to an actual class.
      (if you see backslashes in the pattern string, ignore them – they're necessary so Jira doesn't interpret the curly braces a special characters)

      I tried to get log4j to do what I was after, with the following conversion patterns:

      %c{2.}
      %c{2.1}
      %c{1.2}
      

      All three of these patterns produced "or.ap.so.co.So.Request" in the log. I would have expected the pattern with 1.2 to be the correct one. Is it possible to modify the code so that the number of characters in the abbreviated components can be specified separately from the number of trailing components that are NOT abbreviated?

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              elyograg Shawn Heisey
              Votes:
              2 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: