Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit log prefixes #600

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-600.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: The log collector now omits service name prefixes when collecting logs.
links:
- https://github.com/palantir/docker-compose-rule/pull/600
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.github.zafarkhaja.semver.Version;
import com.google.common.base.Strings;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.palantir.docker.compose.configuration.DockerComposeFiles;
import com.palantir.docker.compose.configuration.ProjectName;
Expand All @@ -31,6 +32,7 @@
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.Validate;
import org.joda.time.Duration;
Expand All @@ -40,12 +42,14 @@
public final class DefaultDockerCompose implements DockerCompose {

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

private final Command command;
private final DockerMachine dockerMachine;
private final DockerComposeExecutable rawExecutable;
private final Supplier<Version> version;

public DefaultDockerCompose(
DockerComposeFiles dockerComposeFiles, DockerMachine dockerMachine, ProjectName projectName) {
Expand All @@ -62,6 +66,14 @@ public DefaultDockerCompose(DockerComposeExecutable rawExecutable, DockerMachine
this.rawExecutable = rawExecutable;
this.command = new Command(rawExecutable, log::trace);
this.dockerMachine = dockerMachine;
this.version = Suppliers.memoize(() -> {
try {
String versionOutput = command.execute(Command.throwingOnError(), "-v");
return DockerComposeVersion.parseFromDockerComposeVersion(versionOutput);
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
});
}

@Override
Expand Down Expand Up @@ -145,12 +157,7 @@ public String run(

private void verifyDockerComposeVersionAtLeast(Version targetVersion, String message)
throws IOException, InterruptedException {
Validate.validState(version().greaterThanOrEqualTo(targetVersion), message);
}

private Version version() throws IOException, InterruptedException {
String versionOutput = command.execute(Command.throwingOnError(), "-v");
return DockerComposeVersion.parseFromDockerComposeVersion(versionOutput);
Validate.validState(version.get().greaterThanOrEqualTo(targetVersion), message);
}

private static String[] constructFullDockerComposeExecArguments(
Expand Down Expand Up @@ -236,7 +243,11 @@ private Optional<String> id(String containerName) throws IOException, Interrupte
private Process logs(String container) throws IOException, InterruptedException {
verifyDockerComposeVersionAtLeast(
VERSION_1_7_0, "You need at least docker-compose 1.7 to run docker-compose logs");
return rawExecutable.execute("logs", "--no-color", container);
if (version.get().lessThan(VERSION_1_28_0)) {
return rawExecutable.execute("logs", "--no-color", container);
} else {
return rawExecutable.execute("logs", "--no-color", "--no-log-prefix", container);
}
}

@Override
Expand Down