Skip to content

Commit

Permalink
Ensure JUL OFF level is respected in liquibase logger (#21)
Browse files Browse the repository at this point in the history
Motivation
----------

An issue was found where the JUL OFF level was being logged at the error level. This is due to how the log level is determined using integer value checks. The ERROR level is the fallback when it should not be.

Modifications
-------------

A reproducer test was written for the issue and the ERROR threshold was checked to fix the issue. The OFF level is now the fallback which does nothing.

Result
------

The result is the JUL OFF level is now respected.
  • Loading branch information
mattbertolini authored Nov 20, 2024
1 parent 3472bdf commit 1735b74
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- '*'
pull_request:
branches:
- $default-branch
- '*'

jobs:
build:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012-2023 Matt Bertolini
* Copyright (c) 2012-2024 Matt Bertolini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
Expand Down Expand Up @@ -60,12 +60,13 @@
* @author Matt Bertolini
* @see liquibase.logging.Logger
*/
public class Slf4jLogger extends AbstractLogger {
public class Slf4jLogger extends AbstractLogger implements liquibase.logging.Logger {

private static final int TRACE_THRESHOLD = Level.FINEST.intValue();
private static final int DEBUG_THRESHOLD = Level.FINE.intValue();
private static final int INFO_THRESHOLD = Level.INFO.intValue();
private static final int WARN_THRESHOLD = Level.WARNING.intValue();
private static final int ERROR_THRESHOLD = Level.SEVERE.intValue();

private final Logger logger;

Expand All @@ -85,7 +86,7 @@ public void log(Level level, String message, Throwable e) {
logger.info(message, e);
} else if (levelValue <= WARN_THRESHOLD) {
logger.warn(message, e);
} else {
} else if (levelValue <= ERROR_THRESHOLD) {
logger.error(message, e);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012-2023 Matt Bertolini
* Copyright (c) 2012-2024 Matt Bertolini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
Expand Down Expand Up @@ -28,6 +28,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;

/**
Expand Down Expand Up @@ -88,6 +89,12 @@ void logWithFinestLevel() {
verify(delegate).trace(message, (Throwable) null);
}

@Test
void doesNotLogWithOffLevel() {
logger.log(Level.OFF, "should not log", null);
verifyNoInteractions(delegate);
}

// Severe level

@Test
Expand Down

0 comments on commit 1735b74

Please sign in to comment.