diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index cf4b4144560..5dc492f8d63 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -1566,11 +1566,6 @@ following example shows potential logging settings in `application.properties`: logging.level.org.hibernate=ERROR ---- -NOTE: By default, Spring Boot remaps Thymeleaf `INFO` messages so that they are logged at -`DEBUG` level. This helps to reduce noise in the standard log output. See -{sc-spring-boot}/logging/logback/LevelRemappingAppender.{sc-ext}[`LevelRemappingAppender`] -for details of how you can apply remapping in your own configuration. - [[boot-features-custom-log-configuration]] diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/DefaultLogbackConfiguration.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/DefaultLogbackConfiguration.java index 18f8c3ac4d9..914829072b1 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/DefaultLogbackConfiguration.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/DefaultLogbackConfiguration.java @@ -102,10 +102,6 @@ class DefaultLogbackConfiguration { config.conversionRule("clr", ColorConverter.class); config.conversionRule("wex", WhitespaceThrowableProxyConverter.class); config.conversionRule("wEx", ExtendedWhitespaceThrowableProxyConverter.class); - LevelRemappingAppender debugRemapAppender = new LevelRemappingAppender( - "org.springframework.boot"); - config.start(debugRemapAppender); - config.appender("DEBUG_LEVEL_REMAPPER", debugRemapAppender); config.logger("org.apache.catalina.startup.DigesterFactory", Level.ERROR); config.logger("org.apache.catalina.util.LifecycleBase", Level.ERROR); config.logger("org.apache.coyote.http11.Http11NioProtocol", Level.WARN); @@ -113,8 +109,6 @@ class DefaultLogbackConfiguration { config.logger("org.apache.tomcat.util.net.NioSelectorPool", Level.WARN); config.logger("org.eclipse.jetty.util.component.AbstractLifeCycle", Level.ERROR); config.logger("org.hibernate.validator.internal.util.Version", Level.WARN); - config.logger("org.springframework.boot.actuate.endpoint.jmx", null, false, - debugRemapAppender); } private Appender consoleAppender(LogbackConfigurator config) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LevelRemappingAppender.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LevelRemappingAppender.java deleted file mode 100644 index e7ee50510e8..00000000000 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LevelRemappingAppender.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.logging.logback; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import ch.qos.logback.classic.Level; -import ch.qos.logback.classic.Logger; -import ch.qos.logback.classic.LoggerContext; -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.classic.spi.IThrowableProxy; -import ch.qos.logback.classic.spi.LoggerContextVO; -import ch.qos.logback.core.Appender; -import ch.qos.logback.core.AppenderBase; -import org.slf4j.Marker; - -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - -/** - * {@link Appender} that can remap {@link ILoggingEvent} {@link Level}s as they are - * written. - * - * @author Phillip Webb - * @see #setRemapLevels(String) - * @see #setDestinationLogger(String) - */ -public class LevelRemappingAppender extends AppenderBase { - - private static final Map DEFAULT_REMAPS = Collections - .singletonMap(Level.INFO, Level.DEBUG); - - private String destinationLogger = Logger.ROOT_LOGGER_NAME; - - private Map remapLevels = DEFAULT_REMAPS; - - /** - * Create a new {@link LevelRemappingAppender}. - */ - public LevelRemappingAppender() { - } - - /** - * Create a new {@link LevelRemappingAppender} with a specific destination logger. - * @param destinationLogger the destination logger - */ - public LevelRemappingAppender(String destinationLogger) { - this.destinationLogger = destinationLogger; - } - - @Override - protected void append(ILoggingEvent event) { - AppendableLogger logger = getLogger(this.destinationLogger); - Level remapped = this.remapLevels.get(event.getLevel()); - logger.callAppenders(remapped == null ? event : new RemappedLoggingEvent(event)); - } - - protected AppendableLogger getLogger(String name) { - LoggerContext loggerContext = (LoggerContext) this.context; - return new AppendableLogger(loggerContext.getLogger(name)); - } - - /** - * Sets the destination logger that will be used to send remapped events. If not - * specified the root logger is used. - * @param destinationLogger the destinationLogger name - */ - public void setDestinationLogger(String destinationLogger) { - Assert.hasLength(destinationLogger, "DestinationLogger must not be empty"); - this.destinationLogger = destinationLogger; - } - - /** - * Set the remapped level. - * @param remapLevels Comma separated String of remapped levels in the form - * {@literal "FROM->TO"}. For example, {@literal "DEBUG->TRACE,ERROR->WARN"}. - */ - public void setRemapLevels(String remapLevels) { - Assert.hasLength(remapLevels, "RemapLevels must not be empty"); - this.remapLevels = new HashMap<>(); - for (String remap : StringUtils.commaDelimitedListToStringArray(remapLevels)) { - String[] split = StringUtils.split(remap, "->"); - Assert.notNull(split, "Remap element '" + remap + "' must contain '->'"); - this.remapLevels.put(Level.toLevel(split[0]), Level.toLevel(split[1])); - } - } - - /** - * Simple wrapper around a logger that can have events appended. - */ - protected static class AppendableLogger { - - private Logger logger; - - public AppendableLogger(Logger logger) { - this.logger = logger; - } - - public void callAppenders(ILoggingEvent event) { - if (this.logger.isEnabledFor(event.getLevel())) { - this.logger.callAppenders(event); - } - } - - } - - /** - * Decorate an existing {@link ILoggingEvent} changing the level to DEBUG. - */ - private class RemappedLoggingEvent implements ILoggingEvent { - - private final ILoggingEvent event; - - RemappedLoggingEvent(ILoggingEvent event) { - this.event = event; - } - - @Override - public String getThreadName() { - return this.event.getThreadName(); - } - - @Override - public Level getLevel() { - Level remappedLevel = LevelRemappingAppender.this.remapLevels - .get(this.event.getLevel()); - return (remappedLevel == null ? this.event.getLevel() : remappedLevel); - } - - @Override - public String getMessage() { - return this.event.getMessage(); - } - - @Override - public Object[] getArgumentArray() { - return this.event.getArgumentArray(); - } - - @Override - public String getFormattedMessage() { - return this.event.getFormattedMessage(); - } - - @Override - public String getLoggerName() { - return this.event.getLoggerName(); - } - - @Override - public LoggerContextVO getLoggerContextVO() { - return this.event.getLoggerContextVO(); - } - - @Override - public IThrowableProxy getThrowableProxy() { - return this.event.getThrowableProxy(); - } - - @Override - public StackTraceElement[] getCallerData() { - return this.event.getCallerData(); - } - - @Override - public boolean hasCallerData() { - return this.event.hasCallerData(); - } - - @Override - public Marker getMarker() { - return this.event.getMarker(); - } - - @Override - public Map getMDCPropertyMap() { - return this.event.getMDCPropertyMap(); - } - - @Override - @Deprecated - public Map getMdc() { - return this.event.getMDCPropertyMap(); - } - - @Override - public long getTimeStamp() { - return this.event.getTimeStamp(); - } - - @Override - public void prepareForDeferredProcessing() { - this.event.prepareForDeferredProcessing(); - } - - } - -} diff --git a/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/defaults.xml b/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/defaults.xml index 0947dd98e2a..4d761badcf8 100644 --- a/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/defaults.xml +++ b/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/defaults.xml @@ -12,10 +12,6 @@ initialization performed by Boot - - org.springframework.boot - - @@ -23,7 +19,4 @@ initialization performed by Boot - - - diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LevelRemappingAppenderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LevelRemappingAppenderTests.java deleted file mode 100644 index fb4e237b9d8..00000000000 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LevelRemappingAppenderTests.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.logging.logback; - -import ch.qos.logback.classic.Level; -import ch.qos.logback.classic.spi.ILoggingEvent; -import org.junit.Before; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import org.springframework.boot.logging.logback.LevelRemappingAppender.AppendableLogger; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -/** - * Tests for {@link LevelRemappingAppender}. - * - * @author Phillip Webb - */ -public class LevelRemappingAppenderTests { - - private TestableLevelRemappingAppender appender; - - @Mock - private AppendableLogger logger; - - @Captor - private ArgumentCaptor logCaptor; - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - this.appender = spy(new TestableLevelRemappingAppender()); - } - - @Test - public void useRootLoggerIfNoDestination() throws Exception { - this.appender.append(mockLogEvent(Level.INFO)); - verify(this.appender).getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME); - } - - @Test - public void useSpecificDestination() throws Exception { - this.appender.setDestinationLogger("org.mine"); - this.appender.append(mockLogEvent(Level.INFO)); - verify(this.appender).getLogger("org.mine"); - } - - @Test - public void defaultRemapsInfo() throws Exception { - this.appender.append(mockLogEvent(Level.INFO)); - verify(this.logger).callAppenders(this.logCaptor.capture()); - assertThat(this.logCaptor.getValue().getLevel()).isEqualTo(Level.DEBUG); - } - - @Test - public void customRemaps() throws Exception { - this.appender.setRemapLevels("DEBUG->TRACE,ERROR->WARN"); - this.appender.append(mockLogEvent(Level.DEBUG)); - this.appender.append(mockLogEvent(Level.ERROR)); - verify(this.logger, times(2)).callAppenders(this.logCaptor.capture()); - assertThat(this.logCaptor.getAllValues().get(0).getLevel()) - .isEqualTo(Level.TRACE); - assertThat(this.logCaptor.getAllValues().get(1).getLevel()).isEqualTo(Level.WARN); - } - - @Test - public void notRemapped() throws Exception { - this.appender.append(mockLogEvent(Level.TRACE)); - verify(this.logger).callAppenders(this.logCaptor.capture()); - assertThat(this.logCaptor.getAllValues().get(0).getLevel()) - .isEqualTo(Level.TRACE); - } - - private ILoggingEvent mockLogEvent(Level level) { - ILoggingEvent event = mock(ILoggingEvent.class); - given(event.getLevel()).willReturn(level); - return event; - } - - private class TestableLevelRemappingAppender extends LevelRemappingAppender { - - @Override - protected AppendableLogger getLogger(String name) { - return LevelRemappingAppenderTests.this.logger; - } - - } - -}