[slf4j-dev] [JIRA] (SLF4J-425) stack trace is logged despite exception matching a parameter in format string

QOS.CH (JIRA) noreply-jira at qos.ch
Wed Jan 3 00:08:00 CET 2018


Dan Lipofsky created SLF4J-425:
----------------------------------

             Summary: stack trace is logged despite exception matching a parameter in format string
                 Key: SLF4J-425
                 URL: https://jira.qos.ch/browse/SLF4J-425
             Project: SLF4J
          Issue Type: Bug
          Components: Core API
    Affects Versions: 1.7.25
         Environment: Slf4j 1.7.25
Logback 1.2.3
SpringBoot 1.5.9
Java 1.8.0_121
            Reporter: Dan Lipofsky
            Assignee: SLF4J developers list
            Priority: Minor


I want to pass an exception into a parameterized log call and have it *not* log the stacktrace.
According to the [FAQ|https://www.slf4j.org/faq.html#paramException] "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



--
This message was sent by Atlassian JIRA
(v7.3.1#73012)


More information about the slf4j-dev mailing list