|
21 | 21 | import java.lang.reflect.Modifier;
|
22 | 22 | import java.nio.charset.Charset;
|
23 | 23 | import java.nio.charset.StandardCharsets;
|
| 24 | +import java.nio.file.Path; |
24 | 25 | import java.util.Arrays;
|
25 | 26 | import java.util.EnumSet;
|
26 | 27 | import java.util.HashSet;
|
|
90 | 91 | * @author Eddú Meléndez
|
91 | 92 | * @author Scott Frederick
|
92 | 93 | * @author Jonatan Ivanov
|
| 94 | + * @author Moritz Halbritter |
93 | 95 | */
|
94 | 96 | @ExtendWith(OutputCaptureExtension.class)
|
95 | 97 | class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
|
@@ -801,6 +803,29 @@ void whenConfigLocationIsXmlAndHasQueryParametersThenIllegalArgumentExceptionSho
|
801 | 803 | .satisfies((ex) -> assertThat(ex.getCause()).isNotInstanceOf(IllegalArgumentException.class));
|
802 | 804 | }
|
803 | 805 |
|
| 806 | + @Test |
| 807 | + void shouldRespectConsoleThreshold(CapturedOutput output) { |
| 808 | + this.environment.setProperty("logging.threshold.console", "warn"); |
| 809 | + this.loggingSystem.beforeInitialize(); |
| 810 | + initialize(this.initializationContext, null, null); |
| 811 | + this.logger.info("Some info message"); |
| 812 | + this.logger.warn("Some warn message"); |
| 813 | + assertThat(output).doesNotContain("Some info message").contains("Some warn message"); |
| 814 | + } |
| 815 | + |
| 816 | + @Test |
| 817 | + void shouldRespectFileThreshold() { |
| 818 | + this.environment.setProperty("logging.threshold.file", "warn"); |
| 819 | + this.loggingSystem.beforeInitialize(); |
| 820 | + initialize(this.initializationContext, null, getLogFile(null, tmpDir())); |
| 821 | + this.logger.info("Some info message"); |
| 822 | + this.logger.warn("Some warn message"); |
| 823 | + Path file = Path.of(tmpDir(), "spring.log"); |
| 824 | + assertThat(file).content(StandardCharsets.UTF_8) |
| 825 | + .doesNotContain("Some info message") |
| 826 | + .contains("Some warn message"); |
| 827 | + } |
| 828 | + |
804 | 829 | private void initialize(LoggingInitializationContext context, String configLocation, LogFile logFile) {
|
805 | 830 | this.loggingSystem.getSystemProperties((ConfigurableEnvironment) context.getEnvironment()).apply(logFile);
|
806 | 831 | this.loggingSystem.beforeInitialize();
|
|
0 commit comments