Commit d4b11c8f authored by Phillip Webb's avatar Phillip Webb

Attempt to fix test failures on Java 9+

See gh-14453
parent cef635d8
...@@ -19,6 +19,8 @@ package org.springframework.boot.devtools.logger; ...@@ -19,6 +19,8 @@ package org.springframework.boot.devtools.logger;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import org.apache.commons.logging.Log;
import org.springframework.boot.context.event.ApplicationPreparedEvent; import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.boot.logging.DeferredLog; import org.springframework.boot.logging.DeferredLog;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
...@@ -32,21 +34,21 @@ import org.springframework.data.domain.AbstractPageRequest; ...@@ -32,21 +34,21 @@ import org.springframework.data.domain.AbstractPageRequest;
*/ */
public final class DevToolsLogFactory { public final class DevToolsLogFactory {
private static final Map<DeferredLog, Class<?>> logs = new LinkedHashMap<>(); private static final Map<Log, Class<?>> logs = new LinkedHashMap<>();
private DevToolsLogFactory() { private DevToolsLogFactory() {
} }
/** /**
* Get a {@link DeferredLog} instance for the specified source that will be * Get a {@link Log} instance for the specified source that will be automatically
* automatically {@link DeferredLog#switchTo(Class) switched} then the * {@link DeferredLog#switchTo(Class) switched} then the {@link AbstractPageRequest
* {@link AbstractPageRequest context is prepared}. * context is prepared}.
* @param source the source for logging * @param source the source for logging
* @return a {@link DeferredLog} instance * @return a {@link DeferredLog} instance
*/ */
public static DeferredLog getLog(Class<?> source) { public static Log getLog(Class<?> source) {
synchronized (logs) { synchronized (logs) {
DeferredLog log = new DeferredLog(); Log log = new DeferredLog();
logs.put(log, source); logs.put(log, source);
return log; return log;
} }
...@@ -60,7 +62,11 @@ public final class DevToolsLogFactory { ...@@ -60,7 +62,11 @@ public final class DevToolsLogFactory {
@Override @Override
public void onApplicationEvent(ApplicationPreparedEvent event) { public void onApplicationEvent(ApplicationPreparedEvent event) {
synchronized (logs) { synchronized (logs) {
logs.forEach((log, source) -> log.switchTo(source)); logs.forEach((log, source) -> {
if (log instanceof DeferredLog) {
((DeferredLog) log).switchTo(source);
}
});
logs.clear(); logs.clear();
} }
} }
......
...@@ -192,9 +192,7 @@ public class DeferredLog implements Log { ...@@ -192,9 +192,7 @@ public class DeferredLog implements Log {
* @param source the source logger * @param source the source logger
* @param destination the destination logger class * @param destination the destination logger class
* @return the destination * @return the destination
* @deprecated since 2.1.0 in favor of {@link #switchTo(Class)}
*/ */
@Deprecated
public static Log replay(Log source, Class<?> destination) { public static Log replay(Log source, Class<?> destination) {
return replay(source, LogFactory.getLog(destination)); return replay(source, LogFactory.getLog(destination));
} }
...@@ -204,9 +202,7 @@ public class DeferredLog implements Log { ...@@ -204,9 +202,7 @@ public class DeferredLog implements Log {
* @param source the source logger * @param source the source logger
* @param destination the destination logger * @param destination the destination logger
* @return the destination * @return the destination
* @deprecated since 2.1.0 in favor of {@link #switchTo(Log)}
*/ */
@Deprecated
public static Log replay(Log source, Log destination) { public static Log replay(Log source, Log destination) {
if (source instanceof DeferredLog) { if (source instanceof DeferredLog) {
((DeferredLog) source).replayTo(destination); ((DeferredLog) source).replayTo(destination);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment