|
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;
|
|
87 | 88 | * @author Robert Thornton
|
88 | 89 | * @author Eddú Meléndez
|
89 | 90 | * @author Scott Frederick
|
| 91 | + * @author Moritz Halbritter |
90 | 92 | */
|
91 | 93 | @ExtendWith(OutputCaptureExtension.class)
|
92 | 94 | class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
|
@@ -706,6 +708,29 @@ void whenConfigLocationIsXmlAndHasQueryParametersThenIllegalArgumentExceptionSho
|
706 | 708 | .satisfies((ex) -> assertThat(ex.getCause()).isNotInstanceOf(IllegalArgumentException.class));
|
707 | 709 | }
|
708 | 710 |
|
| 711 | + @Test |
| 712 | + void shouldRespectConsoleThreshold(CapturedOutput output) { |
| 713 | + this.environment.setProperty("logging.threshold.console", "warn"); |
| 714 | + this.loggingSystem.beforeInitialize(); |
| 715 | + initialize(this.initializationContext, null, null); |
| 716 | + this.logger.info("Some info message"); |
| 717 | + this.logger.warn("Some warn message"); |
| 718 | + assertThat(output).doesNotContain("Some info message").contains("Some warn message"); |
| 719 | + } |
| 720 | + |
| 721 | + @Test |
| 722 | + void shouldRespectFileThreshold() { |
| 723 | + this.environment.setProperty("logging.threshold.file", "warn"); |
| 724 | + this.loggingSystem.beforeInitialize(); |
| 725 | + initialize(this.initializationContext, null, getLogFile(null, tmpDir())); |
| 726 | + this.logger.info("Some info message"); |
| 727 | + this.logger.warn("Some warn message"); |
| 728 | + Path file = Path.of(tmpDir(), "spring.log"); |
| 729 | + assertThat(file).content(StandardCharsets.UTF_8) |
| 730 | + .doesNotContain("Some info message") |
| 731 | + .contains("Some warn message"); |
| 732 | + } |
| 733 | + |
709 | 734 | private void initialize(LoggingInitializationContext context, String configLocation, LogFile logFile) {
|
710 | 735 | this.loggingSystem.getSystemProperties((ConfigurableEnvironment) context.getEnvironment()).apply(logFile);
|
711 | 736 | this.loggingSystem.initialize(context, configLocation, logFile);
|
|
0 commit comments