diff --git a/api/client/commands.go b/api/client/commands.go index 787a2bdc7d..ec72194ac3 100644 --- a/api/client/commands.go +++ b/api/client/commands.go @@ -1616,7 +1616,7 @@ func (cli *DockerCli) CmdEvents(args ...string) error { loc = time.FixedZone(time.Now().Zone()) ) var setTime = func(key, value string) { - format := "2006-01-02 15:04:05 -0700 MST" + format := time.RFC3339Nano if len(value) < len(format) { format = format[:len(value)] } diff --git a/docs/sources/reference/commandline/cli.md b/docs/sources/reference/commandline/cli.md index 9a6d27f0eb..182eb2a221 100644 --- a/docs/sources/reference/commandline/cli.md +++ b/docs/sources/reference/commandline/cli.md @@ -425,24 +425,24 @@ You'll need two shells for this example. **Shell 1: (Again .. now showing events):** - [2013-09-03 15:49:26 +0200 CEST] 4386fb97867d: (from 12de384bfb10) start - [2013-09-03 15:49:29 +0200 CEST] 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) start + 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from 12de384bfb10) die + 2014-05-10T17:42:14.999999999Z07:00 4386fb97867d: (from 12de384bfb10) stop **Show events in the past from a specified time:** $ sudo docker events --since 1378216169 - [2013-09-03 15:49:29 +0200 CEST] 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) die + 2014-03-10T17:42:14.999999999Z07:00 4386fb97867d: (from 12de384bfb10) stop $ sudo docker events --since '2013-09-03' - [2013-09-03 15:49:26 +0200 CEST] 4386fb97867d: (from 12de384bfb10) start - [2013-09-03 15:49:29 +0200 CEST] 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) start + 2014-09-03T17:42:14.999999999Z07:00 4386fb97867d: (from 12de384bfb10) die + 2014-09-03T17:42:14.999999999Z07:00 4386fb97867d: (from 12de384bfb10) stop $ sudo docker events --since '2013-09-03 15:49:29 +0200 CEST' - [2013-09-03 15:49:29 +0200 CEST] 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) die + 2014-09-03T15:49:29.999999999Z07:00 4386fb97867d: (from 12de384bfb10) stop ## 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 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 Usage: docker port CONTAINER PRIVATE_PORT diff --git a/integration-cli/docker_cli_logs_test.go b/integration-cli/docker_cli_logs_test.go index 8b1d006626..b32b7344b4 100644 --- a/integration-cli/docker_cli_logs_test.go +++ b/integration-cli/docker_cli_logs_test.go @@ -98,11 +98,11 @@ func TestLogsTimestamps(t *testing.T) { t.Fatalf("Expected log %d lines, received %d\n", testLen+1, len(lines)) } - ts := regexp.MustCompile(`^\[.*?\]`) + ts := regexp.MustCompile(`^.* `) for _, l := range lines { if l != "" { - _, err := time.Parse("["+time.StampMilli+"]", ts.FindString(l)) + _, err := time.Parse(time.RFC3339Nano+" ", ts.FindString(l)) if err != nil { t.Fatalf("Failed to parse timestamp from %v: %v", l, err) } diff --git a/server/server.go b/server/server.go index 2bbada5a1d..40995da5c4 100644 --- a/server/server.go +++ b/server/server.go @@ -2212,7 +2212,7 @@ func (srv *Server) ContainerLogs(job *engine.Job) engine.Status { return job.Errorf("You must choose at least one stream") } if times { - format = time.StampMilli + format = time.RFC3339Nano } if tail == "" { tail = "all" @@ -2277,7 +2277,7 @@ func (srv *Server) ContainerLogs(job *engine.Job) engine.Status { } logLine := l.Log 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 { fmt.Fprintf(job.Stdout, "%s", logLine) diff --git a/utils/jsonmessage.go b/utils/jsonmessage.go index 66fdcae5a8..922f3df739 100644 --- a/utils/jsonmessage.go +++ b/utils/jsonmessage.go @@ -95,7 +95,7 @@ func (jm *JSONMessage) Display(out io.Writer, isTerminal bool) error { return nil } 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 != "" { fmt.Fprintf(out, "%s: ", jm.ID)