Update logging defaults to show class packaging info and log cause first
This commit updates the default logging configuration for both Logback and Log4J 2 to include class packaging information when logging exceptions and to log the root cause first. Closes gh-3398 Closes gh-3399
This commit is contained in:
parent
f76197066c
commit
b396d0d291
|
|
@ -48,10 +48,10 @@ class DefaultLogbackConfiguration {
|
|||
private static final String CONSOLE_LOG_PATTERN = "%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} "
|
||||
+ "%clr(%5p) %clr(${PID:- }){magenta} %clr(---){faint} "
|
||||
+ "%clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} "
|
||||
+ "%clr(:){faint} %m%n%wex";
|
||||
+ "%clr(:){faint} %m%n%rEx";
|
||||
|
||||
private static final String FILE_LOG_PATTERN = "%d{yyyy-MM-dd HH:mm:ss.SSS} %5p "
|
||||
+ "${PID:- } --- [%t] %-40.40logger{39} : %m%n%wex";
|
||||
+ "${PID:- } --- [%t] %-40.40logger{39} : %m%n%rEx";
|
||||
|
||||
private static final Charset UTF8 = Charset.forName("UTF-8");
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
<Configuration status="WARN">
|
||||
<Properties>
|
||||
<Property name="PID">????</Property>
|
||||
<Property name="LOG_PATTERN">%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${sys:PID} --- [%t] %-40.40c{1.} : %m%n%wEx</Property>
|
||||
<Property name="LOG_PATTERN">%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${sys:PID} --- [%t] %-40.40c{1.} : %m%n%rEx</Property>
|
||||
</Properties>
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT" follow="true">
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
<Configuration status="WARN">
|
||||
<Properties>
|
||||
<Property name="PID">????</Property>
|
||||
<Property name="LOG_PATTERN">%clr{%d{yyyy-MM-dd HH:mm:ss.SSS}}{faint} %clr{%5p} %clr{${sys:PID}}{magenta} %clr{---}{faint} %clr{[%15.15t]}{faint} %clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n%wEx</Property>
|
||||
<Property name="LOG_PATTERN">%clr{%d{yyyy-MM-dd HH:mm:ss.SSS}}{faint} %clr{%5p} %clr{${sys:PID}}{magenta} %clr{---}{faint} %clr{[%15.15t]}{faint} %clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n%rEx</Property>
|
||||
</Properties>
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT" follow="true">
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ initialization performed by Boot
|
|||
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
|
||||
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
|
||||
|
||||
<property name="CONSOLE_LOG_PATTERN" value="%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex"/>
|
||||
<property name="FILE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${PID:- } --- [%t] %-40.40logger{39} : %m%n%wex"/>
|
||||
<property name="CONSOLE_LOG_PATTERN" value="%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%rEx"/>
|
||||
<property name="FILE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${PID:- } --- [%t] %-40.40logger{39} : %m%n%rEx"/>
|
||||
|
||||
<appender name="DEBUG_LEVEL_REMAPPER" class="org.springframework.boot.logging.logback.LevelRemappingAppender">
|
||||
<destinationLogger>org.springframework.boot</destinationLogger>
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ import org.springframework.util.StringUtils;
|
|||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.Matchers.arrayContaining;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
|
@ -186,6 +186,26 @@ public class Log4J2LoggingSystemTests extends AbstractLoggingSystemTests {
|
|||
"log4j2.jsn", "log4j2.xml")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exceptionsIncludeClassPackaging() throws Exception {
|
||||
this.loggingSystem.beforeInitialize();
|
||||
this.logger.info("Hidden");
|
||||
this.loggingSystem.initialize(null, null, null);
|
||||
this.output.expect(containsString("[junit-"));
|
||||
this.logger.warn("Expected exception", new RuntimeException("Expected"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rootCauseIsLoggedFirst() throws Exception {
|
||||
this.loggingSystem.beforeInitialize();
|
||||
this.logger.info("Hidden");
|
||||
this.loggingSystem.initialize(null, null, null);
|
||||
this.output
|
||||
.expect(containsString("Wrapped by: java.lang.RuntimeException: Expected"));
|
||||
this.logger.warn("Expected exception", new RuntimeException("Expected",
|
||||
new RuntimeException("Cause")));
|
||||
}
|
||||
|
||||
private static class TestLog4J2LoggingSystem extends Log4J2LoggingSystem {
|
||||
|
||||
private List<String> availableClasses = new ArrayList<String>();
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ import org.springframework.util.StringUtils;
|
|||
import ch.qos.logback.classic.Logger;
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
|
@ -237,6 +238,26 @@ public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
|
|||
getLineWithText(file, "Hello world").contains("INFO"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exceptionsIncludeClassPackaging() throws Exception {
|
||||
this.loggingSystem.beforeInitialize();
|
||||
this.logger.info("Hidden");
|
||||
this.loggingSystem.initialize(this.initializationContext, null, null);
|
||||
this.output.expect(containsString("[junit-"));
|
||||
this.logger.warn("Expected exception", new RuntimeException("Expected"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rootCauseIsLoggedFirst() throws Exception {
|
||||
this.loggingSystem.beforeInitialize();
|
||||
this.logger.info("Hidden");
|
||||
this.loggingSystem.initialize(this.initializationContext, null, null);
|
||||
this.output
|
||||
.expect(containsString("Wrapped by: java.lang.RuntimeException: Expected"));
|
||||
this.logger.warn("Expected exception", new RuntimeException("Expected",
|
||||
new RuntimeException("Cause")));
|
||||
}
|
||||
|
||||
private String getLineWithText(File file, String outputSearch) throws Exception {
|
||||
return getLineWithText(FileCopyUtils.copyToString(new FileReader(file)),
|
||||
outputSearch);
|
||||
|
|
|
|||
Loading…
Reference in New Issue