@@ -141,7 +141,19 @@ public void onApplicationEvent(ApplicationEvent event) {
141
141
* {@link Environment} and the classpath.
142
142
*/
143
143
protected void initialize (ConfigurableEnvironment environment , ClassLoader classLoader ) {
144
+ initializeEarlyLoggingLevel (environment );
145
+ cleanLogTempProperty ();
146
+ LoggingSystem system = LoggingSystem .get (classLoader );
147
+ boolean systemEnvironmentChanged = mapSystemPropertiesFromSpring (environment );
148
+ if (systemEnvironmentChanged ) {
149
+ // Re-initialize the defaults in case the system Environment changed
150
+ system .beforeInitialize ();
151
+ }
152
+ initializeSystem (environment , system );
153
+ initializeFinalLoggingLevels (environment , system );
154
+ }
144
155
156
+ private void initializeEarlyLoggingLevel (ConfigurableEnvironment environment ) {
145
157
if (this .parseArgs && this .springBootLogging == null ) {
146
158
if (environment .containsProperty ("debug" )) {
147
159
this .springBootLogging = LogLevel .DEBUG ;
@@ -150,7 +162,9 @@ protected void initialize(ConfigurableEnvironment environment, ClassLoader class
150
162
this .springBootLogging = LogLevel .TRACE ;
151
163
}
152
164
}
165
+ }
153
166
167
+ private void cleanLogTempProperty () {
154
168
// Logback won't read backslashes so add a clean path for it to use
155
169
if (!StringUtils .hasLength (System .getProperty ("LOG_TEMP" ))) {
156
170
String path = System .getProperty ("java.io.tmpdir" );
@@ -160,47 +174,48 @@ protected void initialize(ConfigurableEnvironment environment, ClassLoader class
160
174
}
161
175
System .setProperty ("LOG_TEMP" , path );
162
176
}
177
+ }
163
178
164
- boolean environmentChanged = false ;
179
+ private boolean mapSystemPropertiesFromSpring (Environment environment ) {
180
+ boolean changed = false ;
165
181
for (Map .Entry <String , String > mapping : ENVIRONMENT_SYSTEM_PROPERTY_MAPPING
166
182
.entrySet ()) {
167
- if (environment .containsProperty (mapping .getKey ())) {
168
- System .setProperty (mapping .getValue (),
169
- environment .getProperty (mapping .getKey ()));
170
- environmentChanged = true ;
183
+ String springName = mapping .getKey ();
184
+ String systemName = mapping .getValue ();
185
+ if (environment .containsProperty (springName )) {
186
+ System .setProperty (systemName , environment .getProperty (springName ));
187
+ changed = true ;
171
188
}
172
189
}
190
+ return changed ;
191
+ }
173
192
174
- LoggingSystem system = LoggingSystem .get (classLoader );
175
-
176
- if (environmentChanged ) {
177
- // Re-initialize the defaults in case the Environment changed
178
- system .beforeInitialize ();
179
- }
180
- // User specified configuration
193
+ private void initializeSystem (ConfigurableEnvironment environment ,
194
+ LoggingSystem system ) {
181
195
if (environment .containsProperty ("logging.config" )) {
182
196
String value = environment .getProperty ("logging.config" );
183
197
try {
184
198
ResourceUtils .getURL (value ).openStream ().close ();
185
199
system .initialize (value );
186
200
}
187
201
catch (Exception ex ) {
188
- this .logger
189
- .warn ("Logging environment value '"
190
- + value
191
- + "' cannot be opened and will be ignored (using default location instead)" );
202
+ this .logger .warn ("Logging environment value '" + value
203
+ + "' cannot be opened and will be ignored "
204
+ + "(using default location instead)" );
192
205
system .initialize ();
193
206
}
194
207
}
195
208
else {
196
209
system .initialize ();
197
210
}
211
+ }
198
212
213
+ private void initializeFinalLoggingLevels (ConfigurableEnvironment environment ,
214
+ LoggingSystem system ) {
199
215
if (this .springBootLogging != null ) {
200
216
initializeLogLevel (system , this .springBootLogging );
201
217
}
202
218
setLogLevels (system , environment );
203
-
204
219
}
205
220
206
221
public void setLogLevels (LoggingSystem system , Environment environment ) {
0 commit comments