Uploaded image for project: 'SLF4J'
  1. SLF4J
  2. SLF4J-425

stack trace is logged despite exception matching a parameter in format string

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 1.7.25
    • Core API
    • None
    • Slf4j 1.7.25
      Logback 1.2.3
      SpringBoot 1.5.9
      Java 1.8.0_121

    Description

      I want to pass an exception into a parameterized log call and have it not log the stacktrace.
      According to the FAQ "If the exception is not the last argument, it will be treated as a plain object and its stack trace will NOT be printed." which is exactly what I want. 

      But when I try
      LOG.info("foo {} bar {}", "xxx", new RuntimeException("ZZZ"));

      I get
      2018-01-02 15:52:40.637 INFO [main] com.foo.Bar foo xxx bar {}
      java.lang.RuntimeException: ZZZ
          at com.foo.Bar.<init>(Bar.java:37)
          ...

      so it does not substitute that last parameter and it creates an unwanted stacktrace.

      I can work around this by manually calling toString() but this

      • defeats the efficiencies of using a parameterized call
      • probably makes my static analysis tool warn that the exception has not been logged

      edit: I realized my parameter is the last argument, so maybe this behavior doesn't really contradict the FAQ. But the FAQ example shows 2 arguments being passed into a format string with one place holder, and my case has 2 arguments being passed into a format string with 2 place holders, so there is no extra argument. It really seems like this case should not log a stack trace. It should be possible to log without a stack trace; there are many cases where you know the stack trace will not be helpful and there is no reason to fill up the logs with stack traces.

      Attachments

        Activity

          People

            slf4j-dev SLF4J developers list
            dlipofsky Dan Lipofsky
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: