@@ -109,6 +109,31 @@ public class LoggingApplicationListener implements GenericApplicationListener {
109
109
*/
110
110
public static final String EXCEPTION_CONVERSION_WORD = "LOG_EXCEPTION_CONVERSION_WORD" ;
111
111
112
+ /**
113
+ * The name of the System property that contains the log file.
114
+ */
115
+ public static final String LOG_FILE = "LOG_FILE" ;
116
+
117
+ /**
118
+ * The name of the System property that contains the log file.
119
+ */
120
+ public static final String LOG_PATH = "LOG_PATH" ;
121
+
122
+ /**
123
+ * The name of the System property that contains the console log pattern
124
+ */
125
+ public static final String CONSOLE_LOG_PATTERN = "CONSOLE_LOG_PATTERN" ;
126
+
127
+ /**
128
+ * The name of the System property that contains the file log pattern
129
+ */
130
+ public static final String FILE_LOG_PATTERN = "FILE_LOG_PATTERN" ;
131
+
132
+ /**
133
+ * The name of the System property that contains the log level pattern
134
+ */
135
+ public static final String LOG_LEVEL_PATTERN = "LOG_LEVEL_PATTERN" ;
136
+
112
137
/**
113
138
* The name of the {@link LoggingSystem} bean.
114
139
*/
@@ -222,23 +247,38 @@ private void onContextClosedEvent() {
222
247
*/
223
248
protected void initialize (ConfigurableEnvironment environment ,
224
249
ClassLoader classLoader ) {
225
- if (System .getProperty (PID_KEY ) == null ) {
226
- System .setProperty (PID_KEY , new ApplicationPid ().toString ());
227
- }
228
- if (System .getProperty (EXCEPTION_CONVERSION_WORD ) == null ) {
229
- System .setProperty (EXCEPTION_CONVERSION_WORD ,
230
- getExceptionConversionWord (environment ));
231
- }
250
+ LogFile logFile = LogFile .get (environment );
251
+ setSystemProperties (environment , logFile );
232
252
initializeEarlyLoggingLevel (environment );
233
- initializeSystem (environment , this .loggingSystem );
253
+ initializeSystem (environment , this .loggingSystem , logFile );
234
254
initializeFinalLoggingLevels (environment , this .loggingSystem );
235
255
registerShutdownHookIfNecessary (environment , this .loggingSystem );
236
256
}
237
257
238
- private String getExceptionConversionWord (ConfigurableEnvironment environment ) {
239
- RelaxedPropertyResolver resolver = new RelaxedPropertyResolver (environment ,
240
- "logging." );
241
- return resolver .getProperty ("exception-conversion-word" , "%wEx" );
258
+ private void setSystemProperties (ConfigurableEnvironment environment ,
259
+ LogFile logFile ) {
260
+ RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver (
261
+ environment , "logging." );
262
+ setSystemProperty (propertyResolver , EXCEPTION_CONVERSION_WORD ,
263
+ "exception-conversion-word" );
264
+ setSystemProperty (propertyResolver , CONSOLE_LOG_PATTERN , "pattern.console" );
265
+ setSystemProperty (propertyResolver , FILE_LOG_PATTERN , "pattern.file" );
266
+ setSystemProperty (propertyResolver , LOG_LEVEL_PATTERN , "pattern.level" );
267
+ setSystemProperty (PID_KEY , new ApplicationPid ().toString ());
268
+ if (logFile != null ) {
269
+ logFile .applyToSystemProperties ();
270
+ }
271
+ }
272
+
273
+ private void setSystemProperty (RelaxedPropertyResolver propertyResolver ,
274
+ String systemPropertyName , String propertyName ) {
275
+ setSystemProperty (systemPropertyName , propertyResolver .getProperty (propertyName ));
276
+ }
277
+
278
+ private void setSystemProperty (String name , String value ) {
279
+ if (System .getProperty (name ) == null && value != null ) {
280
+ System .setProperty (name , value );
281
+ }
242
282
}
243
283
244
284
private void initializeEarlyLoggingLevel (ConfigurableEnvironment environment ) {
@@ -253,10 +293,9 @@ private void initializeEarlyLoggingLevel(ConfigurableEnvironment environment) {
253
293
}
254
294
255
295
private void initializeSystem (ConfigurableEnvironment environment ,
256
- LoggingSystem system ) {
296
+ LoggingSystem system , LogFile logFile ) {
257
297
LoggingInitializationContext initializationContext = new LoggingInitializationContext (
258
298
environment );
259
- LogFile logFile = LogFile .get (environment );
260
299
String logConfig = environment .getProperty (CONFIG_PROPERTY );
261
300
if (ignoreLogConfig (logConfig )) {
262
301
system .initialize (initializationContext , null , logFile );
0 commit comments