mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-27 12:39:03 +00:00
Merge pull request #46466 from Kguswo
* pr/46466: Polish "Use LogLevel.log() rather than checking the log level manually" Use LogLevel.log() rather than checking the log level manually Closes gh-46466
This commit is contained in:
+2
-13
@@ -166,7 +166,7 @@ public class DeferredLog implements Log {
|
||||
private void log(LogLevel level, Object message, Throwable t) {
|
||||
synchronized (this.lines) {
|
||||
if (this.destination != null) {
|
||||
logTo(this.destination, level, message, t);
|
||||
level.log(this.destination, message, t);
|
||||
}
|
||||
else {
|
||||
this.lines.add(this.destinationSupplier, level, message, t);
|
||||
@@ -216,7 +216,7 @@ public class DeferredLog implements Log {
|
||||
public void replayTo(Log destination) {
|
||||
synchronized (this.lines) {
|
||||
for (Line line : this.lines) {
|
||||
logTo(destination, line.getLevel(), line.getMessage(), line.getThrowable());
|
||||
line.getLevel().log(destination, line.getMessage(), line.getThrowable());
|
||||
}
|
||||
this.lines.clear();
|
||||
}
|
||||
@@ -245,17 +245,6 @@ public class DeferredLog implements Log {
|
||||
return destination;
|
||||
}
|
||||
|
||||
static void logTo(Log log, LogLevel level, Object message, Throwable throwable) {
|
||||
switch (level) {
|
||||
case TRACE -> log.trace(message, throwable);
|
||||
case DEBUG -> log.debug(message, throwable);
|
||||
case INFO -> log.info(message, throwable);
|
||||
case WARN -> log.warn(message, throwable);
|
||||
case ERROR -> log.error(message, throwable);
|
||||
case FATAL -> log.fatal(message, throwable);
|
||||
}
|
||||
}
|
||||
|
||||
static class Lines implements Iterable<Line> {
|
||||
|
||||
private final List<Line> lines = new ArrayList<>();
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ public class DeferredLogs implements DeferredLogFactory {
|
||||
public void switchOverAll() {
|
||||
synchronized (this.lines) {
|
||||
for (Line line : this.lines) {
|
||||
DeferredLog.logTo(line.getDestination(), line.getLevel(), line.getMessage(), line.getThrowable());
|
||||
line.getLevel().log(line.getDestination(), line.getMessage(), line.getThrowable());
|
||||
}
|
||||
for (DeferredLog logger : this.loggers) {
|
||||
logger.switchOver();
|
||||
|
||||
Reference in New Issue
Block a user