19
19
import java .util .LinkedHashMap ;
20
20
import java .util .Map ;
21
21
22
+ import org .apache .commons .logging .Log ;
23
+
22
24
import org .springframework .boot .context .event .ApplicationPreparedEvent ;
23
25
import org .springframework .boot .logging .DeferredLog ;
24
26
import org .springframework .context .ApplicationListener ;
32
34
*/
33
35
public final class DevToolsLogFactory {
34
36
35
- private static final Map <DeferredLog , Class <?>> logs = new LinkedHashMap <>();
37
+ private static final Map <Log , Class <?>> logs = new LinkedHashMap <>();
36
38
37
39
private DevToolsLogFactory () {
38
40
}
39
41
40
42
/**
41
- * Get a {@link DeferredLog } instance for the specified source that will be
42
- * automatically {@link DeferredLog#switchTo(Class) switched} then the
43
- * {@link AbstractPageRequest context is prepared}.
43
+ * Get a {@link Log } instance for the specified source that will be automatically
44
+ * {@link DeferredLog#switchTo(Class) switched} then the {@link AbstractPageRequest
45
+ * context is prepared}.
44
46
* @param source the source for logging
45
47
* @return a {@link DeferredLog} instance
46
48
*/
47
- public static DeferredLog getLog (Class <?> source ) {
49
+ public static Log getLog (Class <?> source ) {
48
50
synchronized (logs ) {
49
- DeferredLog log = new DeferredLog ();
51
+ Log log = new DeferredLog ();
50
52
logs .put (log , source );
51
53
return log ;
52
54
}
@@ -60,7 +62,11 @@ static class Listener implements ApplicationListener<ApplicationPreparedEvent> {
60
62
@ Override
61
63
public void onApplicationEvent (ApplicationPreparedEvent event ) {
62
64
synchronized (logs ) {
63
- logs .forEach ((log , source ) -> log .switchTo (source ));
65
+ logs .forEach ((log , source ) -> {
66
+ if (log instanceof DeferredLog ) {
67
+ ((DeferredLog ) log ).switchTo (source );
68
+ }
69
+ });
64
70
logs .clear ();
65
71
}
66
72
}
0 commit comments