Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message interpolation and exceptions - problem #216

Closed
zorba128 opened this issue Apr 30, 2020 · 1 comment · Fixed by #305
Closed

Message interpolation and exceptions - problem #216

zorba128 opened this issue Apr 30, 2020 · 1 comment · Fixed by #305

Comments

@zorba128
Copy link

zorba128 commented Apr 30, 2020

Just noticed
val e = new RuntimeException(...)
log.info(s"exc: $e")
and
log.info(s"exc: ${e.toString}")
end up with different log messages.

Due to string interpolation conversion error, first one produces:
"exc: {}
java.lang.RuntimeException: Exception
at ...
"
Probbably $e is not treated as argument to slf4j's interpolation, but as exception argument.
So interpolation doesn't work, and one gets unwanted stacktrace.

marcin

@zorba128
Copy link
Author

zorba128 commented Apr 30, 2020

  val abc = "ABC"
  val ex = new RuntimeException("Exception")
  log.error(s"1: $ex")
  log.error(s"2: ${ex.toString}")
  log.error(s"3: $ex, $abc")
  log.error(s"4: $abc, $ex")

produces

[2020-04-30 12:12:39,376] ERROR [main] c.s.x.d.TestLogging:144 - 1: {}
java.lang.RuntimeException: Exception
	at ...
[2020-04-30 12:12:39,376] ERROR [main] c.s.x.d.TestLogging:145 - 2: java.lang.RuntimeException: Exception
[2020-04-30 12:12:39,377] ERROR [main] c.s.x.d.TestLogging:146 - 3: java.lang.RuntimeException: Exception, ABC
[2020-04-30 12:12:39,378] ERROR [main] c.s.x.d.TestLogging:147 - 4: ABC, {}
java.lang.RuntimeException: Exception
	at ...

We're using logback backend if that matters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant