Merge pull request #14565 from izeye:deferred-log
* pr/14565: Add log messages to lines only when the destination isn't set
This commit is contained in:
@@ -142,7 +142,9 @@ public class DeferredLog implements Log {
|
||||
if (this.destination != null) {
|
||||
logTo(this.destination, level, message, t);
|
||||
}
|
||||
this.lines.add(new Line(level, message, t));
|
||||
else {
|
||||
this.lines.add(new Line(level, message, t));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,13 @@
|
||||
|
||||
package org.springframework.boot.logging;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -169,9 +173,21 @@ public class DeferredLogTests {
|
||||
|
||||
@Test
|
||||
public void switchTo() {
|
||||
DirectFieldAccessor deferredLogFieldAccessor = new DirectFieldAccessor(
|
||||
this.deferredLog);
|
||||
List<String> lines = (List<String>) deferredLogFieldAccessor
|
||||
.getPropertyValue("lines");
|
||||
assertThat(lines).isEmpty();
|
||||
|
||||
this.deferredLog.error(this.message, this.throwable);
|
||||
assertThat(lines).hasSize(1);
|
||||
|
||||
this.deferredLog.switchTo(this.log);
|
||||
assertThat(lines).isEmpty();
|
||||
|
||||
this.deferredLog.info("Message2");
|
||||
assertThat(lines).isEmpty();
|
||||
|
||||
verify(this.log).error(this.message, this.throwable);
|
||||
verify(this.log).info("Message2", null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user