Skip to content

Commit ee0b7db

Browse files
author
Yongxing Wang
committed
This add the support for "since" field for logs command.
1 parent 528e676 commit ee0b7db

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* - true or false, if true, print timestamps for every log line. Defaults to false.
1919
* @param tail
2020
* - `all` or `<number>`, Output specified number of lines at the end of logs
21+
* @param since
22+
* - UNIX timestamp (integer) to filter logs. Specifying a timestamp will only output log-entries since that timestamp. Default: 0 (unfiltered)
2123
*/
2224
public interface LogContainerCmd extends AsyncDockerCmd<LogContainerCmd, Frame> {
2325

@@ -33,6 +35,8 @@ public interface LogContainerCmd extends AsyncDockerCmd<LogContainerCmd, Frame>
3335

3436
public boolean hasStderrEnabled();
3537

38+
public int getSince();
39+
3640
public LogContainerCmd withContainerId(String containerId);
3741

3842
/**
@@ -63,6 +67,8 @@ public interface LogContainerCmd extends AsyncDockerCmd<LogContainerCmd, Frame>
6367

6468
public LogContainerCmd withTail(int tail);
6569

70+
public LogContainerCmd withSince(int since);
71+
6672
public static interface Exec extends DockerCmdAsyncExec<LogContainerCmd, Frame> {
6773
}
6874

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* - true or false, if true, print timestamps for every log line. Defaults to false.
1919
* @param tail
2020
* - `all` or `<number>`, Output specified number of lines at the end of logs
21+
* @param since
22+
* - UNIX timestamp (integer) to filter logs. Specifying a timestamp will only output log-entries since that timestamp. Default: 0 (unfiltered)
2123
*/
2224
public class LogContainerCmdImpl extends AbstrAsyncDockerCmd<LogContainerCmd, Frame> implements LogContainerCmd {
2325

@@ -27,6 +29,8 @@ public class LogContainerCmdImpl extends AbstrAsyncDockerCmd<LogContainerCmd, Fr
2729

2830
private boolean followStream, timestamps, stdout, stderr;
2931

32+
private int since = 0;
33+
3034
public LogContainerCmdImpl(LogContainerCmd.Exec exec, String containerId) {
3135
super(exec);
3236
withContainerId(containerId);
@@ -62,6 +66,9 @@ public boolean hasStderrEnabled() {
6266
return stderr;
6367
}
6468

69+
@Override
70+
public int getSince() {return since; }
71+
6572
@Override
6673
public LogContainerCmd withContainerId(String containerId) {
6774
checkNotNull(containerId, "containerId was not specified");
@@ -125,10 +132,18 @@ public LogContainerCmd withTail(int tail) {
125132
return this;
126133
}
127134

135+
@Override
136+
public LogContainerCmd withSince(int since) {
137+
this.since = since;
138+
return this;
139+
}
140+
128141
@Override
129142
public String toString() {
130143
return new StringBuilder("logs ").append(followStream ? "--follow=true" : "")
131-
.append(timestamps ? "--timestamps=true" : "").append(containerId).toString();
144+
.append(timestamps ? "--timestamps=true" : "")
145+
.append(since > 0 ? "--since=" + since : "")
146+
.append(containerId).toString();
132147
}
133148

134149
}

src/main/java/com/github/dockerjava/jaxrs/LogContainerCmdExec.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ protected AbstractCallbackNotifier<Frame> callbackNotifier(LogContainerCmd comma
3131
.queryParam("stdout", command.hasStdoutEnabled() ? "1" : "0")
3232
.queryParam("stderr", command.hasStderrEnabled() ? "1" : "0")
3333
.queryParam("follow", command.hasFollowStreamEnabled() ? "1" : "0")
34+
.queryParam("since", command.getSince())
3435
.queryParam("tail", command.getTail() < 0 ? "all" : "" + command.getTail());
3536

3637
LOGGER.trace("GET: {}", webTarget);

0 commit comments

Comments
 (0)