mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #12557 from rhatdan/journald
Add journald as a supported logger for containers
This commit is contained in:
commit
3dc07162bd
7 changed files with 51 additions and 5 deletions
|
@ -21,6 +21,7 @@ import (
|
|||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/daemon/execdriver"
|
||||
"github.com/docker/docker/daemon/logger"
|
||||
"github.com/docker/docker/daemon/logger/journald"
|
||||
"github.com/docker/docker/daemon/logger/jsonfilelog"
|
||||
"github.com/docker/docker/daemon/logger/syslog"
|
||||
"github.com/docker/docker/daemon/network"
|
||||
|
@ -1421,6 +1422,12 @@ func (container *Container) startLogging() error {
|
|||
return err
|
||||
}
|
||||
l = dl
|
||||
case "journald":
|
||||
dl, err := journald.New(container.ID[:12])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
l = dl
|
||||
case "none":
|
||||
return nil
|
||||
default:
|
||||
|
|
35
daemon/logger/journald/journald.go
Normal file
35
daemon/logger/journald/journald.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package journald
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/coreos/go-systemd/journal"
|
||||
"github.com/docker/docker/daemon/logger"
|
||||
)
|
||||
|
||||
type Journald struct {
|
||||
Jmap map[string]string
|
||||
}
|
||||
|
||||
func New(id string) (logger.Logger, error) {
|
||||
if !journal.Enabled() {
|
||||
return nil, fmt.Errorf("journald is not enabled on this host")
|
||||
}
|
||||
jmap := map[string]string{"MESSAGE_ID": id}
|
||||
return &Journald{Jmap: jmap}, nil
|
||||
}
|
||||
|
||||
func (s *Journald) Log(msg *logger.Message) error {
|
||||
if msg.Source == "stderr" {
|
||||
return journal.Send(string(msg.Line), journal.PriErr, s.Jmap)
|
||||
}
|
||||
return journal.Send(string(msg.Line), journal.PriInfo, s.Jmap)
|
||||
}
|
||||
|
||||
func (s *Journald) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Journald) Name() string {
|
||||
return "Journald"
|
||||
}
|
|
@ -133,7 +133,7 @@ two memory nodes.
|
|||
**--lxc-conf**=[]
|
||||
(lxc exec-driver only) Add custom lxc options --lxc-conf="lxc.cgroup.cpuset.cpus = 0,1"
|
||||
|
||||
**--log-driver**="|*json-file*|*syslog*|*none*"
|
||||
**--log-driver**="|*json-file*|*syslog*|*journald*|*none*"
|
||||
Logging driver for container. Default is defined by daemon `--log-driver` flag.
|
||||
**Warning**: `docker logs` command works only for `json-file` logging driver.
|
||||
|
||||
|
|
|
@ -238,7 +238,7 @@ 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*|*syslog*|*none*"
|
||||
**--log-driver**="|*json-file*|*syslog*|*journald*|*none*"
|
||||
Logging driver for container. Default is defined by daemon `--log-driver` flag.
|
||||
**Warning**: `docker logs` command works only for `json-file` logging driver.
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ unix://[/path/to/socket] to use.
|
|||
**--label**="[]"
|
||||
Set key=value labels to the daemon (displayed in `docker info`)
|
||||
|
||||
**--log-driver**="*json-file*|*syslog*|*none*"
|
||||
**--log-driver**="*json-file*|*syslog*|*journald*|*none*"
|
||||
Default driver for container logs. Default is `json-file`.
|
||||
**Warning**: `docker logs` command works only for `json-file` logging driver.
|
||||
|
||||
|
|
|
@ -261,7 +261,7 @@ Json Parameters:
|
|||
systems, such as SELinux.
|
||||
- **LogConfig** - Log configuration for the container, specified as
|
||||
`{ "Type": "<driver_name>", "Config": {"key1": "val1"}}`.
|
||||
Available types: `json-file`, `syslog`, `none`.
|
||||
Available types: `json-file`, `syslog`, `journald`, `none`.
|
||||
`json-file` logging driver.
|
||||
- **CgroupParent** - Path to cgroups under which the cgroup for the container will be created. If the path is not absolute, the path is considered to be relative to the cgroups path of the init process. Cgroups will be created if they do not already exist.
|
||||
|
||||
|
@ -762,7 +762,7 @@ Json Parameters:
|
|||
systems, such as SELinux.
|
||||
- **LogConfig** - Log configuration for the container, specified as
|
||||
`{ "Type": "<driver_name>", "Config": {"key1": "val1"}}`.
|
||||
Available types: `json-file`, `syslog`, `none`.
|
||||
Available types: `json-file`, `syslog`, `journald`, `none`.
|
||||
`json-file` logging driver.
|
||||
- **CgroupParent** - Path to cgroups under which the cgroup for the container will be created. If the path is not absolute, the path is considered to be relative to the cgroups path of the init process. Cgroups will be created if they do not already exist.
|
||||
|
||||
|
|
|
@ -788,6 +788,10 @@ command is available only for this logging driver
|
|||
Syslog logging driver for Docker. Writes log messages to syslog. `docker logs`
|
||||
command is not available for this logging driver
|
||||
|
||||
#### Logging driver: journald
|
||||
|
||||
Journald logging driver for Docker. Writes log messages to journald. `docker logs` command is not available for this logging driver
|
||||
|
||||
## Overriding Dockerfile image defaults
|
||||
|
||||
When a developer builds an image from a [*Dockerfile*](/reference/builder)
|
||||
|
|
Loading…
Add table
Reference in a new issue