Skip to content

Commit 7af646e

Browse files
committed
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
2 parents 6587e69 + 97b8ce7 commit 7af646e

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/DeferredLog.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public void fatal(Object message, Throwable t) {
166166
private void log(LogLevel level, Object message, Throwable t) {
167167
synchronized (this.lines) {
168168
if (this.destination != null) {
169-
logTo(this.destination, level, message, t);
169+
level.log(this.destination, message, t);
170170
}
171171
else {
172172
this.lines.add(this.destinationSupplier, level, message, t);
@@ -216,7 +216,7 @@ public void replayTo(Class<?> destination) {
216216
public void replayTo(Log destination) {
217217
synchronized (this.lines) {
218218
for (Line line : this.lines) {
219-
logTo(destination, line.getLevel(), line.getMessage(), line.getThrowable());
219+
line.getLevel().log(destination, line.getMessage(), line.getThrowable());
220220
}
221221
this.lines.clear();
222222
}
@@ -245,17 +245,6 @@ public static Log replay(Log source, Log destination) {
245245
return destination;
246246
}
247247

248-
static void logTo(Log log, LogLevel level, Object message, Throwable throwable) {
249-
switch (level) {
250-
case TRACE -> log.trace(message, throwable);
251-
case DEBUG -> log.debug(message, throwable);
252-
case INFO -> log.info(message, throwable);
253-
case WARN -> log.warn(message, throwable);
254-
case ERROR -> log.error(message, throwable);
255-
case FATAL -> log.fatal(message, throwable);
256-
}
257-
}
258-
259248
static class Lines implements Iterable<Line> {
260249

261250
private final List<Line> lines = new ArrayList<>();

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/DeferredLogs.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public Log getLog(Supplier<Log> destination) {
8282
public void switchOverAll() {
8383
synchronized (this.lines) {
8484
for (Line line : this.lines) {
85-
DeferredLog.logTo(line.getDestination(), line.getLevel(), line.getMessage(), line.getThrowable());
85+
line.getLevel().log(line.getDestination(), line.getMessage(), line.getThrowable());
8686
}
8787
for (DeferredLog logger : this.loggers) {
8888
logger.switchOver();

0 commit comments

Comments
 (0)