-
Notifications
You must be signed in to change notification settings - Fork 15
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
DATAGO-73953: use slf4j instead of apache commons logging #330
Conversation
@@ -91,18 +92,18 @@ public void run() { | |||
try { | |||
receive(); | |||
} catch (RuntimeException | UnboundFlowReceiverContainerException e) { | |||
logger.warn(String.format("Exception received while consuming messages from destination %s", | |||
consumerDestination.getName()), e); | |||
LOGGER.warn("Exception received while consuming messages from destination {}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this not going to log as expected: e not logged
/**
* Log a message at the WARN level according to the specified format
* and arguments.
*
* <p>This form avoids superfluous object creation when the logger
* is disabled for the WARN level.
*
* @param format the format string
* @param arg1 the first argument
* @param arg2 the second argument
*/
public void warn(String format, Object arg1, Object arg2);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use parameterized logging with a throwable as the last parameter. See https://www.slf4j.org/faq.html#paramException (Spring Boot 3.3.3 uses SLF4J 2.0.16
).
For example, when I do:
LOGGER.warn("foo {}", "bar", new RuntimeException("test error", new RuntimeException("cause")));
I get the output:
2024-08-28T14:34:34.396-04:00 WARN --- [ main] c.s.s.c.s.b.util.XMLMessageMapperTest : foo bar
java.lang.RuntimeException: test error
Caused by: java.lang.RuntimeException: cause
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
org.slf4j . Logger are bit tricky and may not work as expected
warn(String format, Object arg1, Object arg2);
warn(String msg, Throwable t);
public void warn(String format, Object... arguments);
Use SLF4J instead of Apache Commons Logging.
Although the Spring team themselves uses
LogAccessor
(a wrapper around Apache Commons Logging) throughout the Spring codebase, we should be fine to use SLF4J since the Spring Logging starters allcome with theslfj4j-api
dependency out-of-the-box:spring-boot-starter-logging
spring-boot-starter-log4j2