From b140fd1c4cadf27201ddda059e09e10a01af6f99 Mon Sep 17 00:00:00 2001 From: Dmytro Nosan Date: Fri, 28 Feb 2025 11:34:05 +0200 Subject: [PATCH] Update LogbackLoggingSystemTests to use Console.charset() when available See gh-44477 Signed-off-by: Dmytro Nosan --- .../boot/logging/logback/LogbackLoggingSystemTests.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java index 241c9613e24..8e0f71a07f6 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java @@ -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; @@ -597,7 +598,7 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests { 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 @@ -1156,6 +1157,11 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests { 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;