From 7f7a109acbbcb2f5ba8d3e22a5b4d1bbe1915c66 Mon Sep 17 00:00:00 2001 From: boriswaguia Date: Thu, 5 May 2016 12:37:09 +0100 Subject: [PATCH 1/2] Make it easier to override CONSOLE_LOG_PATTERN when including base.xml Previously, the CONSOLE_LOG_PATTERN property would always be set as a result of base.xml including defaults.xml. This made it hard to override the CONSOLE_LOG_PATTERN as it required a copy and paste of the configuration. This commit updates defaults.xml so that CONSOLE_LOG_PATTERN is only set if it has not already been set. This reduces the configuration to customize the console log pattern to a handful of lines. Closes gh-5632 Closes gh-5867 --- .../org/springframework/boot/logging/logback/defaults.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spring-boot/src/main/resources/org/springframework/boot/logging/logback/defaults.xml b/spring-boot/src/main/resources/org/springframework/boot/logging/logback/defaults.xml index 58ce0d7ea04..70af71b4518 100644 --- a/spring-boot/src/main/resources/org/springframework/boot/logging/logback/defaults.xml +++ b/spring-boot/src/main/resources/org/springframework/boot/logging/logback/defaults.xml @@ -9,8 +9,7 @@ initialization performed by Boot - - + From 1a45e30f37a86c78e6229498ef12a6dae8150cbc Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 10 May 2016 15:25:23 +0100 Subject: [PATCH 2/2] Add a test to verify that the console log pattern can be overridden See gh-5867 --- .../logback/LogbackConfigurationTests.java | 55 +++++++++++++++++++ .../resources/custom-console-log-pattern.xml | 4 ++ 2 files changed, 59 insertions(+) create mode 100644 spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackConfigurationTests.java create mode 100644 spring-boot/src/test/resources/custom-console-log-pattern.xml diff --git a/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackConfigurationTests.java b/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackConfigurationTests.java new file mode 100644 index 00000000000..5054a7194b0 --- /dev/null +++ b/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackConfigurationTests.java @@ -0,0 +1,55 @@ +/* + * Copyright 2012-2016 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.io.File; + +import ch.qos.logback.classic.LoggerContext; +import ch.qos.logback.classic.encoder.PatternLayoutEncoder; +import ch.qos.logback.classic.joran.JoranConfigurator; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.Appender; +import ch.qos.logback.core.ConsoleAppender; +import ch.qos.logback.core.encoder.Encoder; +import ch.qos.logback.core.joran.spi.JoranException; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for default Logback configuration provided by {@code base.xml}. + * + * @author Andy Wilkinson + */ +public class LogbackConfigurationTests { + + @Test + public void consolePatternCanBeOverridden() throws JoranException { + JoranConfigurator configurator = new JoranConfigurator(); + LoggerContext context = new LoggerContext(); + configurator.setContext(context); + configurator.doConfigure( + new File("src/test/resources/custom-console-log-pattern.xml")); + Appender appender = context.getLogger("ROOT") + .getAppender("CONSOLE"); + assertThat(appender).isInstanceOf(ConsoleAppender.class); + Encoder encoder = ((ConsoleAppender) appender).getEncoder(); + assertThat(encoder).isInstanceOf(PatternLayoutEncoder.class); + assertThat(((PatternLayoutEncoder) encoder).getPattern()).isEqualTo("foo"); + } + +} diff --git a/spring-boot/src/test/resources/custom-console-log-pattern.xml b/spring-boot/src/test/resources/custom-console-log-pattern.xml new file mode 100644 index 00000000000..bf800186cec --- /dev/null +++ b/spring-boot/src/test/resources/custom-console-log-pattern.xml @@ -0,0 +1,4 @@ + + + +