From d03901e0ad057a2978368972bc2bd9b782875560 Mon Sep 17 00:00:00 2001 From: Sven Dowideit Date: Tue, 22 Oct 2013 21:48:10 +1000 Subject: [PATCH] Closes #2328 - allow the user to specify a string timestamp (not just a unix epoch) in the string format that the docker cli shows to the user Upstream-commit: 01fea3cf116b768720b542ab65cbd1c2695848d0 Component: engine --- components/engine/commands.go | 14 +++++++++++-- .../engine/docs/sources/commandline/cli.rst | 20 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index d41f0f86b8..00be9a60e1 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -1387,7 +1387,7 @@ func (cli *DockerCli) CmdCommit(args ...string) error { func (cli *DockerCli) CmdEvents(args ...string) error { cmd := Subcmd("events", "[OPTIONS]", "Get real time events from the server") - since := cmd.String("since", "", "Show events previously created (used for polling).") + since := cmd.String("since", "", "Show previously created events and then stream.") if err := cmd.Parse(args); err != nil { return nil } @@ -1399,7 +1399,17 @@ func (cli *DockerCli) CmdEvents(args ...string) error { v := url.Values{} if *since != "" { - v.Set("since", *since) + loc := time.FixedZone(time.Now().Zone()) + format := "2006-01-02 15:04:05 -0700 MST" + if len(*since) < len(format) { + format = format[:len(*since)] + } + + if t, err := time.ParseInLocation(format, *since, loc); err == nil { + v.Set("since", strconv.FormatInt(t.Unix(), 10)) + } else { + v.Set("since", *since) + } } if err := cli.stream("GET", "/events?"+v.Encode(), nil, cli.out, nil); err != nil { diff --git a/components/engine/docs/sources/commandline/cli.rst b/components/engine/docs/sources/commandline/cli.rst index 6d56bccc38..d6e47d1787 100644 --- a/components/engine/docs/sources/commandline/cli.rst +++ b/components/engine/docs/sources/commandline/cli.rst @@ -245,6 +245,9 @@ Full -run example Usage: docker events Get real time events from the server + + -since="": Show previously created events and then stream. + (either seconds since epoch, or date string as below) .. _cli_events_example: @@ -277,6 +280,23 @@ Shell 1: (Again .. now showing events) [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) die [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) stop +Show events in the past from a specified time +............................................. + +.. code-block:: bash + + $ 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 + + $ 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 + + $ 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 .. _cli_export: