diff --git a/daemon/container.go b/daemon/container.go index c189d4feea..bdfcbf4477 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -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: diff --git a/daemon/logger/journald/journald.go b/daemon/logger/journald/journald.go new file mode 100644 index 0000000000..5eb141ac83 --- /dev/null +++ b/daemon/logger/journald/journald.go @@ -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" +} diff --git a/docs/man/docker-create.1.md b/docs/man/docker-create.1.md index bb9cbdc8fc..7aba222b29 100644 --- a/docs/man/docker-create.1.md +++ b/docs/man/docker-create.1.md @@ -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. diff --git a/docs/man/docker-run.1.md b/docs/man/docker-run.1.md index 2893437bbe..f2ce4b7774 100644 --- a/docs/man/docker-run.1.md +++ b/docs/man/docker-run.1.md @@ -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. diff --git a/docs/man/docker.1.md b/docs/man/docker.1.md index 53c54f9037..0196b6364e 100644 --- a/docs/man/docker.1.md +++ b/docs/man/docker.1.md @@ -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. diff --git a/docs/sources/reference/api/docker_remote_api_v1.19.md b/docs/sources/reference/api/docker_remote_api_v1.19.md index 3a4d05ea96..a3b580f1b4 100644 --- a/docs/sources/reference/api/docker_remote_api_v1.19.md +++ b/docs/sources/reference/api/docker_remote_api_v1.19.md @@ -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. diff --git a/docs/sources/reference/run.md b/docs/sources/reference/run.md index 10178b382a..a0d66937f1 100644 --- a/docs/sources/reference/run.md +++ b/docs/sources/reference/run.md @@ -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)