Skip to content

Commit

Permalink
Merge pull request #44477 from nosan
Browse files Browse the repository at this point in the history
* pr/44477:
  Update LogbackLoggingSystemTests to use Console.charset() when available

Closes gh-44477
  • Loading branch information
mhalbritter committed Feb 28, 2025
2 parents f011993 + b140fd1 commit 43075bc
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.boot.logging.logback;

import java.io.Console;
import java.io.File;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand Down Expand Up @@ -597,7 +598,7 @@ void initializeShouldApplyLogbackSystemPropertiesToTheContext() {
expectedProperties.add("CONSOLE_LOG_STRUCTURED_FORMAT");
expectedProperties.add("FILE_LOG_STRUCTURED_FORMAT");
assertThat(properties).containsOnlyKeys(expectedProperties);
assertThat(properties).containsEntry("CONSOLE_LOG_CHARSET", Charset.defaultCharset().name());
assertThat(properties).containsEntry("CONSOLE_LOG_CHARSET", getConsoleCharset());
}

@Test
Expand Down Expand Up @@ -1156,6 +1157,11 @@ private void initialize(LoggingInitializationContext context, String configLocat
this.loggingSystem.initialize(context, configLocation, logFile);
}

private static String getConsoleCharset() {
Console console = System.console();
return (console != null) ? console.charset().name() : Charset.defaultCharset().name();
}

private static Logger getRootLogger() {
ILoggerFactory factory = LoggerFactory.getILoggerFactory();
LoggerContext context = (LoggerContext) factory;
Expand Down

0 comments on commit 43075bc

Please sign in to comment.