Configure context on SizeAndTimeBasedRollingPolicy
Previously, when file-based logging was enabled, Logback would output the following during logging system initialization: LOGBACK: No context given for c.q.l.core.rolling.SizeAndTimeBasedRollingPolicy This commit updates the default logback configuration to set the context on the SizeAndTimeBasedRollingPolicy that it creates. Fixes gh-21056
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
@@ -139,6 +139,7 @@ class DefaultLogbackConfiguration {
|
||||
private void setRollingPolicy(RollingFileAppender<ILoggingEvent> appender, LogbackConfigurator config,
|
||||
String logFile) {
|
||||
SizeAndTimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new SizeAndTimeBasedRollingPolicy<>();
|
||||
rollingPolicy.setContext(config.getContext());
|
||||
rollingPolicy.setCleanHistoryOnStart(
|
||||
this.patterns.getProperty("logging.file.clean-history-on-start", Boolean.class, false));
|
||||
rollingPolicy.setFileNamePattern(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
@@ -111,6 +111,7 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
|
||||
this.loggingSystem.initialize(this.initializationContext, null, getLogFile(null, tmpDir()));
|
||||
this.logger.info("Hello world");
|
||||
File file = new File(tmpDir() + "/spring.log");
|
||||
assertThat(output).doesNotContain("LOGBACK:");
|
||||
assertThat(output).contains("Hello world").doesNotContain("Hidden");
|
||||
assertThat(getLineWithText(output, "Hello world")).contains("INFO");
|
||||
assertThat(file.exists()).isTrue();
|
||||
|
||||
Reference in New Issue
Block a user