Add --since argument to docker logs cmd

Added --since argument to `docker logs` command. Accept unix
timestamps and shows logs only created after the specified date.

Default value is 0 and passing default value or not specifying
the value in the request causes parameter to be ignored (behavior
prior to this change).

Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
This commit is contained in:
Ahmet Alp Balkan 2015-04-14 04:36:12 +00:00
parent b0c6fd961b
commit 9892ab0af7
3 changed files with 29 additions and 4 deletions

View file

@ -32,16 +32,20 @@ func (jl *JSONLog) Reset() {
jl.Created = time.Time{}
}
func WriteLog(src io.Reader, dst io.Writer, format string) error {
func WriteLog(src io.Reader, dst io.Writer, format string, since time.Time) error {
dec := json.NewDecoder(src)
l := &JSONLog{}
for {
l.Reset()
if err := dec.Decode(l); err == io.EOF {
return nil
} else if err != nil {
logrus.Printf("Error streaming logs: %s", err)
return err
}
if !since.IsZero() && l.Created.Before(since) {
continue
}
line, err := l.Format(format)
if err != nil {
return err
@ -49,6 +53,5 @@ func WriteLog(src io.Reader, dst io.Writer, format string) error {
if _, err := io.WriteString(dst, line); err != nil {
return err
}
l.Reset()
}
}