Skip to content

Commit 3be5e6c

Browse files
committed
Polish "Improve logging in DockerApi"
See gh-44412
1 parent 9a94070 commit 3be5e6c

File tree

5 files changed

+12
-110
lines changed

5 files changed

+12
-110
lines changed

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/Builder.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public Builder(DockerConfiguration dockerConfiguration) {
7676
* @param log a logger used to record output
7777
*/
7878
public Builder(BuildLog log) {
79-
this(log, new DockerApi(null, BuildLogDockerLogDelegate.get(log)), null);
79+
this(log, new DockerApi(null, BuildLogAdapter.get(log)), null);
8080
}
8181

8282
/**
@@ -87,7 +87,7 @@ public Builder(BuildLog log) {
8787
*/
8888
public Builder(BuildLog log, DockerConfiguration dockerConfiguration) {
8989
this(log, new DockerApi((dockerConfiguration != null) ? dockerConfiguration.getHost() : null,
90-
BuildLogDockerLogDelegate.get(log)), dockerConfiguration);
90+
BuildLogAdapter.get(log)), dockerConfiguration);
9191
}
9292

9393
Builder(BuildLog log, DockerApi docker, DockerConfiguration dockerConfiguration) {
@@ -264,14 +264,13 @@ private Image pullImage(ImageReference reference, ImageType imageType) throws IO
264264
}
265265

266266
/**
267-
* A {@link DockerLog} implementation that delegates logging to a provided
268-
* {@link AbstractBuildLog}.
267+
* A {@link DockerLog} implementation that adapts to an {@link AbstractBuildLog}.
269268
*/
270-
static final class BuildLogDockerLogDelegate implements DockerLog {
269+
static final class BuildLogAdapter implements DockerLog {
271270

272271
private final AbstractBuildLog log;
273272

274-
private BuildLogDockerLogDelegate(AbstractBuildLog log) {
273+
private BuildLogAdapter(AbstractBuildLog log) {
275274
this.log = log;
276275
}
277276

@@ -284,14 +283,14 @@ public void log(String message) {
284283
* Creates{@link DockerLog} instance based on the provided {@link BuildLog}.
285284
* <p>
286285
* If the provided {@link BuildLog} instance is an {@link AbstractBuildLog}, the
287-
* method returns a {@link BuildLogDockerLogDelegate}, otherwise it returns a
288-
* default {@link DockerLog#toSystemOut()}.
286+
* method returns a {@link BuildLogAdapter}, otherwise it returns a default
287+
* {@link DockerLog#toSystemOut()}.
289288
* @param log the {@link BuildLog} instance to delegate
290289
* @return a {@link DockerLog} instance for logging
291290
*/
292291
static DockerLog get(BuildLog log) {
293-
if (log instanceof AbstractBuildLog) {
294-
return new BuildLogDockerLogDelegate(((AbstractBuildLog) log));
292+
if (log instanceof AbstractBuildLog abstractBuildLog) {
293+
return new BuildLogAdapter(abstractBuildLog);
295294
}
296295
return DockerLog.toSystemOut();
297296
}

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/DockerLog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static DockerLog toSystemOut() {
4848
* @return {@link DockerLog} instance that logs to the given print stream
4949
*/
5050
static DockerLog to(PrintStream out) {
51-
return new PrintStreamDockerLog(out);
51+
return out::println;
5252
}
5353

5454
}

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/PrintStreamDockerLog.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.mockito.ArgumentCaptor;
2626
import org.mockito.stubbing.Answer;
2727

28-
import org.springframework.boot.buildpack.platform.build.Builder.BuildLogDockerLogDelegate;
28+
import org.springframework.boot.buildpack.platform.build.Builder.BuildLogAdapter;
2929
import org.springframework.boot.buildpack.platform.docker.DockerApi;
3030
import org.springframework.boot.buildpack.platform.docker.DockerApi.ContainerApi;
3131
import org.springframework.boot.buildpack.platform.docker.DockerApi.ImageApi;
@@ -84,7 +84,7 @@ void createDockerApiWithLogDockerLogDelegate() {
8484
assertThat(builder).extracting("docker")
8585
.extracting("system")
8686
.extracting("log")
87-
.isInstanceOf(BuildLogDockerLogDelegate.class);
87+
.isInstanceOf(BuildLogAdapter.class);
8888
}
8989

9090
@Test

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/PrintStreamDockerLogTests.java

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)