mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Updated docker logs timestamp to RFC3339
Currently the docker logs timestamp flag generates log entries like: $ sudo docker logs -ft daemon_dave [May 10 13:06:17.934] hello world It uses Go's StampMilli timestamp to generate the timestamp. The entry is also wrapped in [ ]. This is non-standard operational timestamp and one that will require custom parsing. The new timestamp is RFC3999Nano and generates entries like: 2014-05-10T17:42:14.999999999Z07:00 hello world These are readily parsed by tools like ELK. Docker-DCO-1.1-Signed-off-by: James Turnbull <james@lovedthanlost.net> (github: jamtur01) Docker-DCO-1.1-Signed-off-by: Tibor Vass <teabee89@gmail.com> (github: tiborvass)
This commit is contained in:
parent
65a5dde38b
commit
aa0eca03e6
5 changed files with 20 additions and 16 deletions
|
@ -1616,7 +1616,7 @@ func (cli *DockerCli) CmdEvents(args ...string) error {
|
||||||
loc = time.FixedZone(time.Now().Zone())
|
loc = time.FixedZone(time.Now().Zone())
|
||||||
)
|
)
|
||||||
var setTime = func(key, value string) {
|
var setTime = func(key, value string) {
|
||||||
format := "2006-01-02 15:04:05 -0700 MST"
|
format := time.RFC3339Nano
|
||||||
if len(value) < len(format) {
|
if len(value) < len(format) {
|
||||||
format = format[:len(value)]
|
format = format[:len(value)]
|
||||||
}
|
}
|
||||||
|
|
|
@ -425,24 +425,24 @@ You'll need two shells for this example.
|
||||||
|
|
||||||
**Shell 1: (Again .. now showing events):**
|
**Shell 1: (Again .. now showing events):**
|
||||||
|
|
||||||
[2013-09-03 15:49:26 +0200 CEST] 4386fb97867d: (from 12de384bfb10) start
|
2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from 12de384bfb10) start
|
||||||
[2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) die
|
2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from 12de384bfb10) die
|
||||||
[2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) stop
|
2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from 12de384bfb10) stop
|
||||||
|
|
||||||
**Show events in the past from a specified time:**
|
**Show events in the past from a specified time:**
|
||||||
|
|
||||||
$ sudo docker events --since 1378216169
|
$ sudo docker events --since 1378216169
|
||||||
[2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) die
|
2014-03-10T17:42:14.999999999Z07:00 4386fb97867d: (from 12de384bfb10) die
|
||||||
[2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) stop
|
2014-03-10T17:42:14.999999999Z07:00 4386fb97867d: (from 12de384bfb10) stop
|
||||||
|
|
||||||
$ sudo docker events --since '2013-09-03'
|
$ sudo docker events --since '2013-09-03'
|
||||||
[2013-09-03 15:49:26 +0200 CEST] 4386fb97867d: (from 12de384bfb10) start
|
2014-09-03T17:42:14.999999999Z07:00 4386fb97867d: (from 12de384bfb10) start
|
||||||
[2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) die
|
2014-09-03T17:42:14.999999999Z07:00 4386fb97867d: (from 12de384bfb10) die
|
||||||
[2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) stop
|
2014-09-03T17:42:14.999999999Z07:00 4386fb97867d: (from 12de384bfb10) stop
|
||||||
|
|
||||||
$ sudo docker events --since '2013-09-03 15:49:29 +0200 CEST'
|
$ sudo docker events --since '2013-09-03 15:49:29 +0200 CEST'
|
||||||
[2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) die
|
2014-09-03T15:49:29.999999999Z07:00 4386fb97867d: (from 12de384bfb10) die
|
||||||
[2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) stop
|
2014-09-03T15:49:29.999999999Z07:00 4386fb97867d: (from 12de384bfb10) stop
|
||||||
|
|
||||||
## export
|
## export
|
||||||
|
|
||||||
|
@ -750,6 +750,10 @@ the container's `STDOUT` and `STDERR`.
|
||||||
Passing a negative number or a non-integer to `--tail` is invalid and the
|
Passing a negative number or a non-integer to `--tail` is invalid and the
|
||||||
value is set to `all` in that case. This behavior may change in the future.
|
value is set to `all` in that case. This behavior may change in the future.
|
||||||
|
|
||||||
|
The `docker logs --timestamp` commands will add an RFC3339Nano
|
||||||
|
timestamp, for example `2014-05-10T17:42:14.999999999Z07:00`, to each
|
||||||
|
log entry.
|
||||||
|
|
||||||
## port
|
## port
|
||||||
|
|
||||||
Usage: docker port CONTAINER PRIVATE_PORT
|
Usage: docker port CONTAINER PRIVATE_PORT
|
||||||
|
|
|
@ -98,11 +98,11 @@ func TestLogsTimestamps(t *testing.T) {
|
||||||
t.Fatalf("Expected log %d lines, received %d\n", testLen+1, len(lines))
|
t.Fatalf("Expected log %d lines, received %d\n", testLen+1, len(lines))
|
||||||
}
|
}
|
||||||
|
|
||||||
ts := regexp.MustCompile(`^\[.*?\]`)
|
ts := regexp.MustCompile(`^.* `)
|
||||||
|
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
if l != "" {
|
if l != "" {
|
||||||
_, err := time.Parse("["+time.StampMilli+"]", ts.FindString(l))
|
_, err := time.Parse(time.RFC3339Nano+" ", ts.FindString(l))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to parse timestamp from %v: %v", l, err)
|
t.Fatalf("Failed to parse timestamp from %v: %v", l, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2212,7 +2212,7 @@ func (srv *Server) ContainerLogs(job *engine.Job) engine.Status {
|
||||||
return job.Errorf("You must choose at least one stream")
|
return job.Errorf("You must choose at least one stream")
|
||||||
}
|
}
|
||||||
if times {
|
if times {
|
||||||
format = time.StampMilli
|
format = time.RFC3339Nano
|
||||||
}
|
}
|
||||||
if tail == "" {
|
if tail == "" {
|
||||||
tail = "all"
|
tail = "all"
|
||||||
|
@ -2277,7 +2277,7 @@ func (srv *Server) ContainerLogs(job *engine.Job) engine.Status {
|
||||||
}
|
}
|
||||||
logLine := l.Log
|
logLine := l.Log
|
||||||
if times {
|
if times {
|
||||||
logLine = fmt.Sprintf("[%s] %s", l.Created.Format(format), logLine)
|
logLine = fmt.Sprintf("%s %s", l.Created.Format(format), logLine)
|
||||||
}
|
}
|
||||||
if l.Stream == "stdout" && stdout {
|
if l.Stream == "stdout" && stdout {
|
||||||
fmt.Fprintf(job.Stdout, "%s", logLine)
|
fmt.Fprintf(job.Stdout, "%s", logLine)
|
||||||
|
|
|
@ -95,7 +95,7 @@ func (jm *JSONMessage) Display(out io.Writer, isTerminal bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if jm.Time != 0 {
|
if jm.Time != 0 {
|
||||||
fmt.Fprintf(out, "[%s] ", time.Unix(jm.Time, 0))
|
fmt.Fprintf(out, "%s ", time.Unix(jm.Time, 0).Format(time.RFC3339Nano))
|
||||||
}
|
}
|
||||||
if jm.ID != "" {
|
if jm.ID != "" {
|
||||||
fmt.Fprintf(out, "%s: ", jm.ID)
|
fmt.Fprintf(out, "%s: ", jm.ID)
|
||||||
|
|
Loading…
Reference in a new issue