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

DATAGO-73953: use slf4j instead of apache commons logging #330

Merged
merged 1 commit into from
Aug 28, 2024

Conversation

Nephery
Copy link
Collaborator

@Nephery Nephery commented Aug 28, 2024

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 the slfj4j-api dependency out-of-the-box:

  • spring-boot-starter-logging
  • spring-boot-starter-log4j2

@@ -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 {}",
Copy link
Contributor

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);

Copy link
Collaborator Author

@Nephery Nephery Aug 28, 2024

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

Copy link
Contributor

@mgevantmakher mgevantmakher left a 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);

@Nephery Nephery merged commit 9b4c6c3 into SolaceProducts:master Aug 28, 2024
2 checks passed
@Nephery Nephery deleted the use-slf4j branch August 28, 2024 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants