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

Allow stacktrace pattern converters to specify a starting point to ignore redundant framework stack elements

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: In Progress
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • Layouts
    • None

    Description

      Stack traces from applications in well-known environments can be reduced by removing certain bottom components of the stack such as the web container and core framework. For example every exception thrown from an application running on the fictional Acme framework hosted in Tomcat might produce a stack trace like this:

      at example.internal.acme.parser.AcmeMethodInfo$AcmeMethodCallHandler.handleCall(AcmeMethodInfo.java:275)
      at example.xml.ws.DefaultWsiInvocationHandler.invoke(DefaultWsiInvocationHandler.java:56)
      at example.internal.xml.ws.server.WebservicesServletBase.doPost(WebservicesServletBase.java:500)
      at example.internal.xml.ws.server.WebservicesServletBase.doPost(WebservicesServletBase.java:402)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
      at example.internal.xml.ws.server.WebservicesServletBase.service(WebservicesServletBase.java:1080)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      at java.lang.Thread.run(Thread.java:745)
      

      When shipping logs to a log aggregation tool the stack trace could be greatly reduced (sometimes more than 50%) by omitting the unhelpful duplicate code that appears with each exception.

      Its not always possible to catch and re-throw with a reduced stack.

      The exception patterns on this page allow some filtering but I don't want to filter out the entire org.apache or example.internal packages. The depth parameter seems to start from the top:

      https://logging.apache.org/log4j/log4j-2.0/manual/layouts.html

      rException["none"|"short"|"full"|depth],[filters(packages)}
      

      I briefly scanned the code and couldn't tell if depth supported negative numbers. A negative depth could indicate how many lines from the bottom should be skipped. From the example above the value would be "depth=-27". A alternate (better?) way to express a starting point would be to list what to start with. This example removes the web container noise and starts the stack trace closer to meaningful code:

      startWith=javax.servlet.http.HttpServlet.service
      

      This syntax expresses a slightly more accurate starting point and allows for more than one starting point:

      startWith=example.internal.acme.parser.AcmeMethodInfo$AcmeMethodCallHandler.handleCall,javax.servlet.http.HttpServlet.service
      

      Another example of the syntax:

      <properties>
        <property name="startWith">example.internal.acme.parser.AcmeMethodInfo$AcmeMethodCallHandler.handleCall,javax.servlet.http.HttpServlet.service</property>
      </properties>
      
      <PatternLayout pattern="%m%xEx{startWith(${startWith})}%n"/>
      

      I don't know if this should be implemented with simple string manipulation (regex, substring, etc) or actually inspecting each StackTraceElement.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              rgrabowski Ron Grabowski
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: