From 5a3351883b254d3690e9dcc5b89293bcee474493 Mon Sep 17 00:00:00 2001 From: Ivan Babrou Date: Thu, 21 Jan 2016 21:30:48 +0000 Subject: [PATCH] Add tag support to journald logging driver, closes #19556 Signed-off-by: Ivan Babrou --- daemon/logger/journald/journald.go | 9 +++++++++ docs/admin/logging/journald.md | 6 ++++++ docs/admin/logging/log_tags.md | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/daemon/logger/journald/journald.go b/daemon/logger/journald/journald.go index c729b56d19..748dd8b24a 100644 --- a/daemon/logger/journald/journald.go +++ b/daemon/logger/journald/journald.go @@ -12,6 +12,7 @@ import ( "github.com/Sirupsen/logrus" "github.com/coreos/go-systemd/journal" "github.com/docker/docker/daemon/logger" + "github.com/docker/docker/daemon/logger/loggerutils" ) const name = "journald" @@ -48,10 +49,17 @@ func New(ctx logger.Context) (logger.Logger, error) { name = name[1:] } + // parse log tag + tag, err := loggerutils.ParseLogTag(ctx, "") + if err != nil { + return nil, err + } + vars := map[string]string{ "CONTAINER_ID": ctx.ContainerID[:12], "CONTAINER_ID_FULL": ctx.ContainerID, "CONTAINER_NAME": name, + "CONTAINER_TAG": tag, } extraAttrs := ctx.ExtraAttributes(strings.ToTitle) for k, v := range extraAttrs { @@ -67,6 +75,7 @@ func validateLogOpt(cfg map[string]string) error { switch key { case "labels": case "env": + case "tag": default: return fmt.Errorf("unknown log opt '%s' for journald log driver", key) } diff --git a/docs/admin/logging/journald.md b/docs/admin/logging/journald.md index fb06fa98d2..90c9720319 100644 --- a/docs/admin/logging/journald.md +++ b/docs/admin/logging/journald.md @@ -24,6 +24,7 @@ driver stores the following metadata in the journal with each message: | `CONTAINER_ID` | The container ID truncated to 12 characters. | | `CONTAINER_ID_FULL` | The full 64-character container ID. | | `CONTAINER_NAME` | The container name at the time it was started. If you use `docker rename` to rename a container, the new name is not reflected in the journal entries. | +| `CONTAINER_TAG` | The container tag ([log tag option documentation](log_tags.md)). | ## Usage @@ -42,6 +43,11 @@ You can set the logging driver for a specific container by using the Users can use the `--log-opt NAME=VALUE` flag to specify additional journald logging driver options. +### tag + +Specify template to set `CONTAINER_TAG` value in journald logs. Refer to +[log tag option documentation](log_tags.md) for customizing the log tag format. + ### labels and env The `labels` and `env` options each take a comma-separated list of keys. If there is collision between `label` and `env` keys, the value of the `env` takes precedence. Both options add additional metadata in the journal with each message. diff --git a/docs/admin/logging/log_tags.md b/docs/admin/logging/log_tags.md index 29743f8674..9b2e098d9f 100644 --- a/docs/admin/logging/log_tags.md +++ b/docs/admin/logging/log_tags.md @@ -3,7 +3,7 @@ aliases = ["/engine/reference/logging/log_tags/"] title = "Log tags for logging driver" description = "Describes how to format tags for." -keywords = ["docker, logging, driver, syslog, Fluentd, gelf"] +keywords = ["docker, logging, driver, syslog, Fluentd, gelf, journald"] [menu.main] parent = "smn_logging" weight = 1