Skip to content

Commit 43075bc

Browse files
committed
Merge pull request #44477 from nosan
* pr/44477: Update LogbackLoggingSystemTests to use Console.charset() when available Closes gh-44477
2 parents f011993 + b140fd1 commit 43075bc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.logging.logback;
1818

19+
import java.io.Console;
1920
import java.io.File;
2021
import java.lang.annotation.ElementType;
2122
import java.lang.annotation.Retention;
@@ -597,7 +598,7 @@ void initializeShouldApplyLogbackSystemPropertiesToTheContext() {
597598
expectedProperties.add("CONSOLE_LOG_STRUCTURED_FORMAT");
598599
expectedProperties.add("FILE_LOG_STRUCTURED_FORMAT");
599600
assertThat(properties).containsOnlyKeys(expectedProperties);
600-
assertThat(properties).containsEntry("CONSOLE_LOG_CHARSET", Charset.defaultCharset().name());
601+
assertThat(properties).containsEntry("CONSOLE_LOG_CHARSET", getConsoleCharset());
601602
}
602603

603604
@Test
@@ -1156,6 +1157,11 @@ private void initialize(LoggingInitializationContext context, String configLocat
11561157
this.loggingSystem.initialize(context, configLocation, logFile);
11571158
}
11581159

1160+
private static String getConsoleCharset() {
1161+
Console console = System.console();
1162+
return (console != null) ? console.charset().name() : Charset.defaultCharset().name();
1163+
}
1164+
11591165
private static Logger getRootLogger() {
11601166
ILoggerFactory factory = LoggerFactory.getILoggerFactory();
11611167
LoggerContext context = (LoggerContext) factory;

0 commit comments

Comments
 (0)