Skip to content

Commit fc31115

Browse files
committed
Rely soley on underlying logger for isEnabled in Liquibase logger
Previously, CommonsLoggingLiquibaseLogger referred to its configured level and the underlying Commons Logging log when determining if logging was enabled for a particular level. This did not work as intended as setLogLevel was never called leaving the configured level stuck at its default value of INFO. As a result of this any logging at levels below INFO would not be output, irrespective of the configuration of the underlying logging framework. This commit updates CommonsLoggingLiquibaseLogger to rely purely on the Commons Logging log when determining whether or not logging for a particular level is enabled. This brings the implementation into line with liquibase-slf4j [1] which provides similar functionality, albeit using SLF4J rather than Commons Logging Closes gh-2916 [1] https://github.com/mattbertolini/liquibase-slf4j/blob/master/src/main/java/liquibase/ext/logging/slf4j/Slf4jLogger.java
1 parent 4977e48 commit fc31115

File tree

2 files changed

+5
-47
lines changed

2 files changed

+5
-47
lines changed

spring-boot/src/main/java/org/springframework/boot/liquibase/CommonsLoggingLiquibaseLogger.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,11 +16,9 @@
1616

1717
package org.springframework.boot.liquibase;
1818

19-
import liquibase.configuration.LiquibaseConfiguration;
2019
import liquibase.logging.LogLevel;
2120
import liquibase.logging.Logger;
2221
import liquibase.logging.core.AbstractLogger;
23-
import liquibase.logging.core.DefaultLoggerConfiguration;
2422

2523
import org.apache.commons.logging.Log;
2624
import org.apache.commons.logging.LogFactory;
@@ -30,6 +28,7 @@
3028
*
3129
* @author Michael Cramer
3230
* @author Phillip Webb
31+
* @author Andy Wilkinson
3332
* @since 1.2.0
3433
*/
3534
public class CommonsLoggingLiquibaseLogger extends AbstractLogger {
@@ -119,7 +118,7 @@ public int getPriority() {
119118
}
120119

121120
private boolean isEnabled(LogLevel level) {
122-
if (this.logger != null && getLogLevel().compareTo(level) <= 0) {
121+
if (this.logger != null) {
123122
switch (level) {
124123
case DEBUG:
125124
return this.logger.isDebugEnabled();
@@ -134,14 +133,4 @@ private boolean isEnabled(LogLevel level) {
134133
return false;
135134
}
136135

137-
@Override
138-
public LogLevel getLogLevel() {
139-
LogLevel logLevel = super.getLogLevel();
140-
if (logLevel == null) {
141-
return toLogLevel(LiquibaseConfiguration.getInstance()
142-
.getConfiguration(DefaultLoggerConfiguration.class).getLogLevel());
143-
}
144-
return logLevel;
145-
}
146-
147136
}

spring-boot/src/test/java/org/springframework/boot/liquibase/CommonsLoggingLiquibaseLoggerTests.java

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@
3131
* Tests for {@link CommonsLoggingLiquibaseLogger}.
3232
*
3333
* @author Phillip Webb
34+
* @author Andy Wilkinson
3435
*/
3536
public class CommonsLoggingLiquibaseLoggerTests {
3637

@@ -70,14 +71,6 @@ public void debugWithLoggerOff() {
7071
verify(this.delegate, never()).debug("debug");
7172
}
7273

73-
@Test
74-
public void debugBelowLevel() {
75-
this.logger.setLogLevel(LogLevel.INFO);
76-
given(this.delegate.isDebugEnabled()).willReturn(true);
77-
this.logger.debug("debug", this.ex);
78-
verify(this.delegate, never()).debug("debug", this.ex);
79-
}
80-
8174
@Test
8275
public void info() {
8376
this.logger.setLogLevel(LogLevel.INFO);
@@ -102,14 +95,6 @@ public void infoWithLoggerOff() {
10295
verify(this.delegate, never()).info("info");
10396
}
10497

105-
@Test
106-
public void infoBelowLevel() {
107-
this.logger.setLogLevel(LogLevel.WARNING);
108-
given(this.delegate.isInfoEnabled()).willReturn(true);
109-
this.logger.info("info", this.ex);
110-
verify(this.delegate, never()).info("info", this.ex);
111-
}
112-
11398
@Test
11499
public void warning() {
115100
this.logger.setLogLevel(LogLevel.WARNING);
@@ -134,14 +119,6 @@ public void warningWithLoggerOff() {
134119
verify(this.delegate, never()).warn("warning");
135120
}
136121

137-
@Test
138-
public void warningBelowLevel() {
139-
this.logger.setLogLevel(LogLevel.SEVERE);
140-
given(this.delegate.isWarnEnabled()).willReturn(true);
141-
this.logger.warning("warning", this.ex);
142-
verify(this.delegate, never()).warn("warning", this.ex);
143-
}
144-
145122
@Test
146123
public void severe() {
147124
this.logger.setLogLevel(LogLevel.SEVERE);
@@ -166,14 +143,6 @@ public void severeWithLoggerOff() {
166143
verify(this.delegate, never()).error("severe");
167144
}
168145

169-
@Test
170-
public void severeBelowLevel() {
171-
this.logger.setLogLevel(LogLevel.OFF);
172-
given(this.delegate.isErrorEnabled()).willReturn(true);
173-
this.logger.severe("severe", this.ex);
174-
verify(this.delegate, never()).error("severe", this.ex);
175-
}
176-
177146
private class MockCommonsLoggingLiquibaseLogger extends CommonsLoggingLiquibaseLogger {
178147

179148
@Override

0 commit comments

Comments
 (0)