Signed-off-by: Alexander Morozov <lk4d4@docker.com>
| ... | ... |
@@ -2,6 +2,7 @@ package client |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"encoding/json" |
| 5 |
+ "fmt" |
|
| 5 | 6 |
"net/url" |
| 6 | 7 |
"time" |
| 7 | 8 |
|
| ... | ... |
@@ -11,6 +12,11 @@ import ( |
| 11 | 11 |
"github.com/docker/docker/pkg/timeutils" |
| 12 | 12 |
) |
| 13 | 13 |
|
| 14 |
+var validDrivers = map[string]bool{
|
|
| 15 |
+ "json-file": true, |
|
| 16 |
+ "journald": true, |
|
| 17 |
+} |
|
| 18 |
+ |
|
| 14 | 19 |
// CmdLogs fetches the logs of a given container. |
| 15 | 20 |
// |
| 16 | 21 |
// docker logs [OPTIONS] CONTAINER |
| ... | ... |
@@ -36,6 +42,10 @@ func (cli *DockerCli) CmdLogs(args ...string) error {
|
| 36 | 36 |
return err |
| 37 | 37 |
} |
| 38 | 38 |
|
| 39 |
+ if !validDrivers[c.HostConfig.LogConfig.Type] {
|
|
| 40 |
+ return fmt.Errorf("\"logs\" command is supported only for \"json-file\" and \"journald\" logging drivers (got: %s)", c.HostConfig.LogConfig.Type)
|
|
| 41 |
+ } |
|
| 42 |
+ |
|
| 39 | 43 |
v := url.Values{}
|
| 40 | 44 |
v.Set("stdout", "1")
|
| 41 | 45 |
v.Set("stderr", "1")
|
| ... | ... |
@@ -1242,10 +1242,10 @@ func (s *DockerDaemonSuite) TestDaemonLoggingDriverNoneLogsError(c *check.C) {
|
| 1242 | 1242 |
} |
| 1243 | 1243 |
id := strings.TrimSpace(out) |
| 1244 | 1244 |
out, err = s.d.Cmd("logs", id)
|
| 1245 |
- if err != nil {
|
|
| 1246 |
- c.Fatalf("Logs request should be sent and then fail with \"none\" driver")
|
|
| 1245 |
+ if err == nil {
|
|
| 1246 |
+ c.Fatalf("Logs should fail with 'none' driver")
|
|
| 1247 | 1247 |
} |
| 1248 |
- if !strings.Contains(out, `Error running logs job: Failed to get logging factory: logger: no log driver named 'none' is registered`) {
|
|
| 1248 |
+ if !strings.Contains(out, `"logs" command is supported only for "json-file" and "journald" logging drivers (got: none)`) {
|
|
| 1249 | 1249 |
c.Fatalf("There should be an error about none not being a recognized log driver, got: %s", out)
|
| 1250 | 1250 |
} |
| 1251 | 1251 |
} |