From e37e329074517f48db8468affc62beb595ab090e Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Fri, 6 Nov 2015 11:40:48 -0800 Subject: [PATCH] Return nice client-side message for docker logs Signed-off-by: Alexander Morozov --- api/client/logs.go | 10 ++++++++++ integration-cli/docker_cli_daemon_test.go | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/api/client/logs.go b/api/client/logs.go index f6704542b9..6de7b1332d 100644 --- a/api/client/logs.go +++ b/api/client/logs.go @@ -2,6 +2,7 @@ package client import ( "encoding/json" + "fmt" "net/url" "time" @@ -11,6 +12,11 @@ import ( "github.com/docker/docker/pkg/timeutils" ) +var validDrivers = map[string]bool{ + "json-file": true, + "journald": true, +} + // CmdLogs fetches the logs of a given container. // // docker logs [OPTIONS] CONTAINER @@ -36,6 +42,10 @@ func (cli *DockerCli) CmdLogs(args ...string) error { return err } + if !validDrivers[c.HostConfig.LogConfig.Type] { + return fmt.Errorf("\"logs\" command is supported only for \"json-file\" and \"journald\" logging drivers (got: %s)", c.HostConfig.LogConfig.Type) + } + v := url.Values{} v.Set("stdout", "1") v.Set("stderr", "1") diff --git a/integration-cli/docker_cli_daemon_test.go b/integration-cli/docker_cli_daemon_test.go index fb8b2d5366..8d24df8c57 100644 --- a/integration-cli/docker_cli_daemon_test.go +++ b/integration-cli/docker_cli_daemon_test.go @@ -1242,10 +1242,10 @@ func (s *DockerDaemonSuite) TestDaemonLoggingDriverNoneLogsError(c *check.C) { } id := strings.TrimSpace(out) out, err = s.d.Cmd("logs", id) - if err != nil { - c.Fatalf("Logs request should be sent and then fail with \"none\" driver") + if err == nil { + c.Fatalf("Logs should fail with 'none' driver") } - if !strings.Contains(out, `Error running logs job: Failed to get logging factory: logger: no log driver named 'none' is registered`) { + if !strings.Contains(out, `"logs" command is supported only for "json-file" and "journald" logging drivers (got: none)`) { c.Fatalf("There should be an error about none not being a recognized log driver, got: %s", out) } }