18
18
19
19
import java .io .Console ;
20
20
import java .nio .charset .Charset ;
21
+ import java .nio .charset .StandardCharsets ;
21
22
import java .util .function .BiConsumer ;
22
23
import java .util .function .Function ;
23
24
@@ -95,10 +96,6 @@ protected Console getConsole() {
95
96
return System .console ();
96
97
}
97
98
98
- protected Charset getDefaultCharset () {
99
- return Charset .defaultCharset ();
100
- }
101
-
102
99
public final void apply () {
103
100
apply (null );
104
101
}
@@ -120,11 +117,14 @@ private PropertyResolver getPropertyResolver() {
120
117
}
121
118
122
119
protected void apply (LogFile logFile , PropertyResolver resolver ) {
120
+ Charset defaultCharset = getDefaultCharset ();
121
+ Charset consoleCharset = (defaultCharset != null ) ? defaultCharset : getDefaultConsoleCharset ();
122
+ Charset fileCharset = (defaultCharset != null ) ? defaultCharset : getDefaultFileCharset ();
123
123
setSystemProperty (LoggingSystemProperty .APPLICATION_NAME , resolver );
124
124
setSystemProperty (LoggingSystemProperty .APPLICATION_GROUP , resolver );
125
125
setSystemProperty (LoggingSystemProperty .PID , new ApplicationPid ().toString ());
126
- setSystemProperty (LoggingSystemProperty .CONSOLE_CHARSET , resolver , getConsoleCharset () .name ());
127
- setSystemProperty (LoggingSystemProperty .FILE_CHARSET , resolver , getDefaultCharset () .name ());
126
+ setSystemProperty (LoggingSystemProperty .CONSOLE_CHARSET , resolver , consoleCharset .name ());
127
+ setSystemProperty (LoggingSystemProperty .FILE_CHARSET , resolver , fileCharset .name ());
128
128
setSystemProperty (LoggingSystemProperty .CONSOLE_THRESHOLD , resolver , this ::thresholdMapper );
129
129
setSystemProperty (LoggingSystemProperty .FILE_THRESHOLD , resolver , this ::thresholdMapper );
130
130
setSystemProperty (LoggingSystemProperty .EXCEPTION_CONVERSION_WORD , resolver );
@@ -140,9 +140,32 @@ protected void apply(LogFile logFile, PropertyResolver resolver) {
140
140
}
141
141
}
142
142
143
- private Charset getConsoleCharset () {
143
+ /**
144
+ * Returns the default charset.
145
+ * @return the default charset
146
+ * @deprecated since 3.5.0 for removal in 3.7.0 in favor of
147
+ * {@link #getDefaultConsoleCharset()} and {@link #getDefaultFileCharset()}.
148
+ */
149
+ @ Deprecated (since = "3.5.0" , forRemoval = true )
150
+ protected Charset getDefaultCharset () {
151
+ return null ;
152
+ }
153
+
154
+ /**
155
+ * Returns the default console charset.
156
+ * @return returns the default console charset
157
+ */
158
+ protected Charset getDefaultConsoleCharset () {
144
159
Console console = getConsole ();
145
- return (console != null ) ? console .charset () : getDefaultCharset ();
160
+ return (console != null ) ? console .charset () : Charset .defaultCharset ();
161
+ }
162
+
163
+ /**
164
+ * Returns the default file charset.
165
+ * @return returns the default file charset
166
+ */
167
+ protected Charset getDefaultFileCharset () {
168
+ return StandardCharsets .UTF_8 ;
146
169
}
147
170
148
171
private void setSystemProperty (LoggingSystemProperty property , PropertyResolver resolver ) {
0 commit comments