[logback-user] Doubt on exception as last parameter behavior
Fabio Cechinel Veronez
fabio.veronez at gmail.com
Thu Nov 14 14:17:18 CET 2019
Hello all,
I have a question regarding the behavior of an exception as last parameter.
It is very well known that an exception placed as last parameter will
have a special handling, having its stack trace printed available in
the final output. Ex:
```
logger.warn("Printing a value {} with exception's stacktrace", 23, new
Exception("some message"));
```
Outputs something like:
```
11:35:01.696 [main] WARN App - Printing a value 23 with exception's stacktrace
java.lang.Exception: some message
at App.main(App.java:7) ~[classes/:na]
```
My question is: what if the message string contains an interpolation
expression for that exception parameter? Example:
```
logger.warn("Printing a value {} with an inlined exception {}", 23,
new Exception("some message"));
```
Personally I would expect that in this case the exception would be
printed just like any other regular parameter, not having its
stracktrace printed. Basically, I would expected an exception to have
a special handling only when it is the "+1" parameter.
It seems to have been the case up to logback-classic:1.0.13
(slf4j-api:1.7.5). Using this version the log statement above prints:
```
11:35:01.699 [main] WARN App - Printing a value 23 with an inlined
exception java.lang.Exception: some message
```
While using logback-classic:1.2.3 (slf4j-api:1.7.25) it prints:
```
11:38:02.150 [main] WARN App - Printing a value 23 with an inlined exception {}
java.lang.Exception: some message
at App.main(App.java:8)
```
Apparently the behaviour changed from logback:1.1.0 onwards.
Is this a new expected behavior?
Unfortunately I couldn't find in the documentation where the expected
behavior of this particular situation is explained in more details. So
I thought it to be a bit ambiguous. If there one, please, let me know.
Thanks in advance.
--
Fabio Cechinel Veronez
More information about the logback-user
mailing list