Fail docker logs on all logging drivers apart from 'json-file'

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
Alexander Morozov 2015-02-05 16:24:47 -08:00
parent dd6d2cd660
commit bdf3a0295d
11 changed files with 67 additions and 3 deletions

View file

@ -1929,6 +1929,10 @@ func (cli *DockerCli) CmdLogs(args ...string) error {
return err
}
if env.GetSubEnv("HostConfig").GetSubEnv("LogConfig").Get("Type") != "json-file" {
return fmt.Errorf("\"logs\" command is supported only for \"json-file\" logging driver")
}
v := url.Values{}
v.Set("stdout", "1")
v.Set("stderr", "1")

View file

@ -1489,3 +1489,12 @@ func (container *Container) getNetworkedContainer() (*Container, error) {
func (container *Container) Stats() (*execdriver.ResourceStats, error) {
return container.daemon.Stats(container)
}
func (c *Container) LogDriverType() string {
c.Lock()
defer c.Unlock()
if c.hostConfig.LogConfig.Type == "" {
return c.daemon.defaultLogConfig.Type
}
return c.hostConfig.LogConfig.Type
}

View file

@ -44,6 +44,9 @@ func (daemon *Daemon) ContainerLogs(job *engine.Job) engine.Status {
if err != nil {
return job.Error(err)
}
if container.LogDriverType() != "json-file" {
return job.Errorf("\"logs\" endpoint is supported only for \"json-file\" logging driver")
}
cLog, err := container.ReadLog("json")
if err != nil && os.IsNotExist(err) {
// Legacy logs

View file

@ -26,6 +26,7 @@ docker-create - Create a new container
[**--ipc**[=*IPC*]]
[**--link**[=*[]*]]
[**--lxc-conf**[=*[]*]]
[**--log-driver**[=*[]*]]
[**-m**|**--memory**[=*MEMORY*]]
[**--memory-swap**[=*MEMORY-SWAP*]]
[**--mac-address**[=*MAC-ADDRESS*]]
@ -108,6 +109,10 @@ IMAGE [COMMAND] [ARG...]
**--lxc-conf**=[]
(lxc exec-driver only) Add custom lxc options --lxc-conf="lxc.cgroup.cpuset.cpus = 0,1"
**--log-driver**="|*json-file*|*none*"
Logging driver for container. Default is defined by daemon `--log-driver` flag.
**Warning**: `docker logs` command works only for `json-file` logging driver.
**-m**, **--memory**=""
Memory limit (format: <number><optional unit>, where unit = b, k, m or g)

View file

@ -22,6 +22,8 @@ The **docker logs --follow** command combines commands **docker logs** and
**docker attach**. It will first return all logs from the beginning and
then continue streaming new output from the containers stdout and stderr.
**Warning**: This command works only for **json-file** logging driver.
# OPTIONS
**--help**
Print usage statement

View file

@ -27,6 +27,7 @@ docker-run - Run a command in a new container
[**--ipc**[=*IPC*]]
[**--link**[=*[]*]]
[**--lxc-conf**[=*[]*]]
[**--log-driver**[=*[]*]]
[**-m**|**--memory**[=*MEMORY*]]
[**--memory-swap**[=*MEMORY-SWAP]]
[**--mac-address**[=*MAC-ADDRESS*]]
@ -209,6 +210,10 @@ which interface and port to use.
**--lxc-conf**=[]
(lxc exec-driver only) Add custom lxc options --lxc-conf="lxc.cgroup.cpuset.cpus = 0,1"
**--log-driver**="|*json-file*|*none*"
Logging driver for container. Default is defined by daemon `--log-driver` flag.
**Warning**: `docker logs` command works only for `json-file` logging driver.
**-m**, **--memory**=""
Memory limit (format: <number><optional unit>, where unit = b, k, m or g)

View file

@ -82,6 +82,10 @@ unix://[/path/to/socket] to use.
**--label**="[]"
Set key=value labels to the daemon (displayed in `docker info`)
**--log-driver**="*json-file*|*none*"
Container's logging driver. Default is `default`.
**Warning**: `docker logs` command works only for `json-file` logging driver.
**--mtu**=VALUE
Set the containers network mtu. Default is `1500`.

View file

@ -252,6 +252,7 @@ Json Parameters:
- **LogConfig** - Logging configuration to container, format
`{ "Type": "<driver_name>", "Config": {"key1": "val1"}}
Available types: `json-file`, `none`.
`json-file` logging driver.
Query Parameters:
@ -441,6 +442,9 @@ Status Codes:
Get stdout and stderr logs from the container ``id``
> **Note**:
> This endpoint works only for containers with `json-file` logging driver.
**Example request**:
GET /containers/4fa6e0f0c678/logs?stderr=1&stdout=1&timestamps=1&follow=1&tail=10 HTTP/1.1

View file

@ -1405,6 +1405,9 @@ For example:
-t, --timestamps=false Show timestamps
--tail="all" Number of lines to show from the end of the logs
NOTE: this command is available only for containers with `json-file` logging
driver.
The `docker logs` command batch-retrieves logs present at the time of execution.
The `docker logs --follow` command will continue streaming the new output from

View file

@ -565,13 +565,15 @@ familiar with using LXC directly.
You can specify a different logging driver for the container than for the daemon.
### Log driver: none
### Logging driver: none
Disables any logging for the container.
Disables any logging for the container. `docker logs` won't be available with
this driver.
### Log driver: json-file
Default logging driver for Docker. Writes JSON messages to file.
Default logging driver for Docker. Writes JSON messages to file. `docker logs`
command is available only for this logging driver
## Overriding Dockerfile image defaults

View file

@ -703,3 +703,26 @@ func TestDaemonLoggingDriverNoneOverride(t *testing.T) {
}
logDone("daemon - 'none' logging driver override in run")
}
func TestDaemonLoggingDriverNoneLogsError(t *testing.T) {
d := NewDaemon(t)
if err := d.StartWithBusybox("--log-driver=none"); err != nil {
t.Fatal(err)
}
defer d.Stop()
out, err := d.Cmd("run", "-d", "busybox", "echo", "testline")
if err != nil {
t.Fatal(out, err)
}
id := strings.TrimSpace(out)
out, err = d.Cmd("logs", id)
if err == nil {
t.Fatalf("Logs should fail with \"none\" driver")
}
if !strings.Contains(out, `\"logs\" command is supported only for \"json-file\" logging driver`) {
t.Fatalf("There should be error about non-json-file driver, got %s", out)
}
logDone("daemon - logs not available for non-json-file drivers")
}