Skip to content

Commit ef9abb1

Browse files
committed
Omit log prefixes
1 parent a7e4928 commit ef9abb1

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

docker-compose-rule-core/src/main/java/com/palantir/docker/compose/execution/DefaultDockerCompose.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import com.github.zafarkhaja.semver.Version;
1919
import com.google.common.base.Strings;
20+
import com.google.common.base.Supplier;
21+
import com.google.common.base.Suppliers;
2022
import com.google.common.collect.ImmutableList;
2123
import com.palantir.docker.compose.configuration.DockerComposeFiles;
2224
import com.palantir.docker.compose.configuration.ProjectName;
@@ -40,12 +42,14 @@
4042
public final class DefaultDockerCompose implements DockerCompose {
4143

4244
public static final Version VERSION_1_7_0 = Version.valueOf("1.7.0");
45+
public static final Version VERSION_1_28_0 = Version.valueOf("1.28.0");
4346
private static final Duration LOG_TIMEOUT = Duration.standardMinutes(1);
4447
private static final Logger log = LoggerFactory.getLogger(DefaultDockerCompose.class);
4548

4649
private final Command command;
4750
private final DockerMachine dockerMachine;
4851
private final DockerComposeExecutable rawExecutable;
52+
private final Supplier<Version> version;
4953

5054
public DefaultDockerCompose(
5155
DockerComposeFiles dockerComposeFiles, DockerMachine dockerMachine, ProjectName projectName) {
@@ -62,6 +66,14 @@ public DefaultDockerCompose(DockerComposeExecutable rawExecutable, DockerMachine
6266
this.rawExecutable = rawExecutable;
6367
this.command = new Command(rawExecutable, log::trace);
6468
this.dockerMachine = dockerMachine;
69+
this.version = Suppliers.memoize(() -> {
70+
try {
71+
String versionOutput = command.execute(Command.throwingOnError(), "-v");
72+
return DockerComposeVersion.parseFromDockerComposeVersion(versionOutput);
73+
} catch (IOException | InterruptedException e) {
74+
throw new RuntimeException(e);
75+
}
76+
});
6577
}
6678

6779
@Override
@@ -145,12 +157,7 @@ public String run(
145157

146158
private void verifyDockerComposeVersionAtLeast(Version targetVersion, String message)
147159
throws IOException, InterruptedException {
148-
Validate.validState(version().greaterThanOrEqualTo(targetVersion), message);
149-
}
150-
151-
private Version version() throws IOException, InterruptedException {
152-
String versionOutput = command.execute(Command.throwingOnError(), "-v");
153-
return DockerComposeVersion.parseFromDockerComposeVersion(versionOutput);
160+
Validate.validState(version.get().greaterThanOrEqualTo(targetVersion), message);
154161
}
155162

156163
private static String[] constructFullDockerComposeExecArguments(
@@ -236,7 +243,11 @@ private Optional<String> id(String containerName) throws IOException, Interrupte
236243
private Process logs(String container) throws IOException, InterruptedException {
237244
verifyDockerComposeVersionAtLeast(
238245
VERSION_1_7_0, "You need at least docker-compose 1.7 to run docker-compose logs");
239-
return rawExecutable.execute("logs", "--no-color", container);
246+
if (version.get().lessThan(VERSION_1_28_0)) {
247+
return rawExecutable.execute("logs", "--no-color", container);
248+
} else {
249+
return rawExecutable.execute("logs", "--no-color", "--no-log-prefix", container);
250+
}
240251
}
241252

242253
@Override

0 commit comments

Comments
 (0)