diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/DeferredLog.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/DeferredLog.java index cf5f7b4713..05026a362d 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/DeferredLog.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/DeferredLog.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,7 +35,7 @@ import org.springframework.util.Assert; */ public class DeferredLog implements Log { - private volatile Log destination; + private Log destination; private final Supplier destinationSupplier; @@ -175,7 +175,9 @@ public class DeferredLog implements Log { } void switchOver() { - this.destination = this.destinationSupplier.get(); + synchronized (this.lines) { + this.destination = this.destinationSupplier.get(); + } } /**