Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
* @param tail
* - `all` or `<number>`, Output specified number of lines at the end of logs
* @param since
* - UNIX timestamp, RFC 3339 date, or Go duration string to filter logs.
* Specifying a timestamp will only output log-entries since that timestamp. Default: 0 (unfiltered)
* - UNIX timestamp (integer) to filter logs. Specifying a timestamp will only output log-entries since that timestamp. Default:
* 0 (unfiltered)
*/
public interface LogContainerCmd extends AsyncDockerCmd<LogContainerCmd, Frame> {

Expand All @@ -47,7 +47,7 @@ public interface LogContainerCmd extends AsyncDockerCmd<LogContainerCmd, Frame>
Boolean hasStderrEnabled();

@CheckForNull
String getSince();
Integer getSince();

LogContainerCmd withContainerId(@Nonnull String containerId);

Expand All @@ -67,7 +67,7 @@ public interface LogContainerCmd extends AsyncDockerCmd<LogContainerCmd, Frame>

LogContainerCmd withTail(Integer tail);

LogContainerCmd withSince(String since);
LogContainerCmd withSince(Integer since);

/**
* @throws com.github.dockerjava.api.NotFoundException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@
* @param tail
* - `all` or `<number>`, Output specified number of lines at the end of logs
* @param since
* - UNIX timestamp, RFC 3339 date, or Go duration string to filter logs.
* Specifying a timestamp will only output log-entries since that timestamp. Default: 0 (unfiltered)
* - UNIX timestamp (integer) to filter logs. Specifying a timestamp will only output log-entries since that timestamp. Default:
* 0 (unfiltered)
*/
public class LogContainerCmdImpl extends AbstrAsyncDockerCmd<LogContainerCmd, Frame> implements LogContainerCmd {

private String containerId;

private Boolean followStream, timestamps, stdout, stderr;

private Integer tail;
private String since;
private Integer tail, since;

public LogContainerCmdImpl(LogContainerCmd.Exec exec, String containerId) {
super(exec);
Expand Down Expand Up @@ -70,7 +69,7 @@ public Boolean hasStderrEnabled() {
}

@Override
public String getSince() {
public Integer getSince() {
return since;
}

Expand Down Expand Up @@ -118,7 +117,7 @@ public LogContainerCmd withTail(Integer tail) {
}

@Override
public LogContainerCmd withSince(String since) {
public LogContainerCmd withSince(Integer since) {
this.since = since;
return this;
}
Expand Down
36 changes: 1 addition & 35 deletions src/test/java/com/github/dockerjava/cmd/LogContainerCmdIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void asyncLogContainerWithSince() throws Exception {
LOG.info("Created container: {}", container.toString());
assertThat(container.getId(), not(isEmptyString()));

String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
int timestamp = (int) (System.currentTimeMillis() / 1000);

dockerRule.getClient().startContainerCmd(container.getId()).exec();

Expand All @@ -197,38 +197,4 @@ public void asyncLogContainerWithSince() throws Exception {

assertThat(loggingCallback.toString(), containsString(snippet));
}

@Test
public void asyncLogContainerWithSinceNanoseconds() throws Exception {
String snippet = "hello world";

CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox")
.withCmd("/bin/echo", snippet)
.exec();

LOG.info("Created container: {}", container.toString());
assertThat(container.getId(), not(isEmptyString()));

String timestamp = String.format("%.4f", System.currentTimeMillis() / 1000d);
dockerRule.getClient().startContainerCmd(container.getId()).exec();

int exitCode = dockerRule.getClient().waitContainerCmd(container.getId())
.exec(new WaitContainerResultCallback())
.awaitStatusCode();

assertThat(exitCode, equalTo(0));

LogContainerTestCallback loggingCallback = new LogContainerTestCallback();

dockerRule.getClient().logContainerCmd(container.getId())
.withStdErr(true)
.withStdOut(true)
.withTimestamps(true)
.withSince(timestamp)
.exec(loggingCallback);

loggingCallback.awaitCompletion();

assertThat(loggingCallback.toString(), containsString(snippet));
}
}