Skip to content

Commit d0af7f8

Browse files
committed
#9 When a finite process exits on error, it will log the entire Docker error log at ERROR level.
1 parent 0e51d76 commit d0af7f8

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

src/main/java/nl/_42/boot/docker/utils/DockerFiniteProcessRunner.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,18 @@ public DockerFiniteProcessRunner( String command,
3333
public DockerOutputResult execute() throws IOException {
3434
int exitValue = processRunner.execute();
3535

36-
if (exitValue != 0) {
36+
DockerOutputResult result = new DockerOutputResult(
37+
readFile(stdOutFilename, Charset.defaultCharset()),
38+
readFile(stdErrFilename, Charset.defaultCharset()),
39+
exitValue);
40+
41+
if (result.getExitCode() != 0) {
42+
result.logErrLines();
3743
LOGGER.error("| Docker command: " + command + " failed to execute");
3844
throw new ExceptionInInitializerError("Docker command: " + command + " failed to execute");
3945
}
4046

41-
return new DockerOutputResult(
42-
readFile(stdOutFilename, Charset.defaultCharset()),
43-
readFile(stdErrFilename, Charset.defaultCharset()),
44-
exitValue);
47+
return result;
4548
}
4649

4750
static String readFile(String path, Charset encoding)

src/main/java/nl/_42/boot/docker/utils/DockerOutputResult.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
package nl._42.boot.docker.utils;
22

3+
import org.apache.commons.lang3.StringUtils;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
6+
37
public class DockerOutputResult {
48

9+
private static final Logger LOGGER = LoggerFactory.getLogger(DockerOutputResult.class);
10+
511
private String stdOut;
612
private String stdErr;
713
private Integer exitCode;
14+
private String[] errLines = new String[0];
815

916
public DockerOutputResult(String stdOut, String stdErr, Integer exitCode) {
1017
this.stdOut = stdOut;
1118
this.stdErr = stdErr;
1219
this.exitCode = exitCode;
20+
if (!StringUtils.isBlank(stdErr)) {
21+
errLines = stdErr.split("\\r\\n|\\n|\\r");
22+
}
1323
}
1424

1525
public String getStdOut() {
@@ -24,4 +34,13 @@ public Integer getExitCode() {
2434
return exitCode;
2535
}
2636

37+
public String[] getErrLines() {
38+
return errLines;
39+
}
40+
41+
public void logErrLines() {
42+
for (String line : getErrLines()) {
43+
LOGGER.error("| > " + line);
44+
}
45+
}
2746
}

0 commit comments

Comments
 (0)