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 (integer) to filter logs. Specifying a timestamp will only output log-entries since that timestamp. Default:
* 0 (unfiltered)
* - 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)
*/
public interface LogContainerCmd extends AsyncDockerCmd<LogContainerCmd, Frame> {

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

@CheckForNull
Integer getSince();
String 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(Integer since);
LogContainerCmd withSince(String since);

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

private String containerId;

private Boolean followStream, timestamps, stdout, stderr;

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

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

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

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

@Override
public LogContainerCmd withSince(Integer since) {
public LogContainerCmd withSince(String since) {
this.since = since;
return this;
}
Expand Down
36 changes: 35 additions & 1 deletion 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()));

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

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

Expand All @@ -197,4 +197,38 @@ 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));
}
}