mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #6931 from tiborvass/merge-5723
Updated docker logs timestamp to RFC3339 (carrying #5723)
This commit is contained in:
commit
519319b989
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())
|
||||
)
|
||||
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)]
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue