Skip to content

Commit 80c6213

Browse files
authored
Merge pull request docker-java#1111 from caspergreen/feature/log-cmd-to-string
Change since parameter in LogContainerCmd to String
2 parents 66232b6 + 43cc601 commit 80c6213

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

src/main/java/com/github/dockerjava/api/command/LogContainerCmd.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
* @param tail
2424
* - `all` or `<number>`, Output specified number of lines at the end of logs
2525
* @param since
26-
* - UNIX timestamp (integer) to filter logs. Specifying a timestamp will only output log-entries since that timestamp. Default:
27-
* 0 (unfiltered)
26+
* - UNIX timestamp, RFC 3339 date, or Go duration string to filter logs.
27+
* Specifying a timestamp will only output log-entries since that timestamp. Default: 0 (unfiltered)
2828
*/
2929
public interface LogContainerCmd extends AsyncDockerCmd<LogContainerCmd, Frame> {
3030

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

4949
@CheckForNull
50-
Integer getSince();
50+
String getSince();
5151

5252
LogContainerCmd withContainerId(@Nonnull String containerId);
5353

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

6868
LogContainerCmd withTail(Integer tail);
6969

70-
LogContainerCmd withSince(Integer since);
70+
LogContainerCmd withSince(String since);
7171

7272
/**
7373
* @throws com.github.dockerjava.api.NotFoundException

src/main/java/com/github/dockerjava/core/command/LogContainerCmdImpl.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@
2222
* @param tail
2323
* - `all` or `<number>`, Output specified number of lines at the end of logs
2424
* @param since
25-
* - UNIX timestamp (integer) to filter logs. Specifying a timestamp will only output log-entries since that timestamp. Default:
26-
* 0 (unfiltered)
25+
* - UNIX timestamp, RFC 3339 date, or Go duration string to filter logs.
26+
* Specifying a timestamp will only output log-entries since that timestamp. Default: 0 (unfiltered)
2727
*/
2828
public class LogContainerCmdImpl extends AbstrAsyncDockerCmd<LogContainerCmd, Frame> implements LogContainerCmd {
2929

3030
private String containerId;
3131

3232
private Boolean followStream, timestamps, stdout, stderr;
3333

34-
private Integer tail, since;
34+
private Integer tail;
35+
private String since;
3536

3637
public LogContainerCmdImpl(LogContainerCmd.Exec exec, String containerId) {
3738
super(exec);
@@ -69,7 +70,7 @@ public Boolean hasStderrEnabled() {
6970
}
7071

7172
@Override
72-
public Integer getSince() {
73+
public String getSince() {
7374
return since;
7475
}
7576

@@ -117,7 +118,7 @@ public LogContainerCmd withTail(Integer tail) {
117118
}
118119

119120
@Override
120-
public LogContainerCmd withSince(Integer since) {
121+
public LogContainerCmd withSince(String since) {
121122
this.since = since;
122123
return this;
123124
}

src/test/java/com/github/dockerjava/cmd/LogContainerCmdIT.java

+35-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public void asyncLogContainerWithSince() throws Exception {
175175
LOG.info("Created container: {}", container.toString());
176176
assertThat(container.getId(), not(isEmptyString()));
177177

178-
int timestamp = (int) (System.currentTimeMillis() / 1000);
178+
String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
179179

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

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

198198
assertThat(loggingCallback.toString(), containsString(snippet));
199199
}
200+
201+
@Test
202+
public void asyncLogContainerWithSinceNanoseconds() throws Exception {
203+
String snippet = "hello world";
204+
205+
CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox")
206+
.withCmd("/bin/echo", snippet)
207+
.exec();
208+
209+
LOG.info("Created container: {}", container.toString());
210+
assertThat(container.getId(), not(isEmptyString()));
211+
212+
String timestamp = String.format("%.4f", System.currentTimeMillis() / 1000d);
213+
dockerRule.getClient().startContainerCmd(container.getId()).exec();
214+
215+
int exitCode = dockerRule.getClient().waitContainerCmd(container.getId())
216+
.exec(new WaitContainerResultCallback())
217+
.awaitStatusCode();
218+
219+
assertThat(exitCode, equalTo(0));
220+
221+
LogContainerTestCallback loggingCallback = new LogContainerTestCallback();
222+
223+
dockerRule.getClient().logContainerCmd(container.getId())
224+
.withStdErr(true)
225+
.withStdOut(true)
226+
.withTimestamps(true)
227+
.withSince(timestamp)
228+
.exec(loggingCallback);
229+
230+
loggingCallback.awaitCompletion();
231+
232+
assertThat(loggingCallback.toString(), containsString(snippet));
233+
}
200234
}

0 commit comments

Comments
 (0)