From 11a24f19c2da88b6c3b50114863f24c06c5ce2fd Mon Sep 17 00:00:00 2001 From: Daniel Dao Date: Sun, 4 Oct 2015 21:06:19 +0000 Subject: [PATCH] add labels/env log option for journald this allows journald logger to collect extra metadata from containers with `--log-opt labels=label1,label2 --log-opt env=env1,env2` Signed-off-by: Daniel Dao --- daemon/logger/journald/journald.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/daemon/logger/journald/journald.go b/daemon/logger/journald/journald.go index bc4302fb3b..c729b56d19 100644 --- a/daemon/logger/journald/journald.go +++ b/daemon/logger/journald/journald.go @@ -6,6 +6,7 @@ package journald import ( "fmt" + "strings" "sync" "github.com/Sirupsen/logrus" @@ -46,10 +47,16 @@ func New(ctx logger.Context) (logger.Logger, error) { if name[0] == '/' { name = name[1:] } + vars := map[string]string{ "CONTAINER_ID": ctx.ContainerID[:12], "CONTAINER_ID_FULL": ctx.ContainerID, - "CONTAINER_NAME": name} + "CONTAINER_NAME": name, + } + extraAttrs := ctx.ExtraAttributes(strings.ToTitle) + for k, v := range extraAttrs { + vars[k] = v + } return &journald{vars: vars, readers: readerList{readers: make(map[*logger.LogWatcher]*logger.LogWatcher)}}, nil } @@ -58,6 +65,8 @@ func New(ctx logger.Context) (logger.Logger, error) { func validateLogOpt(cfg map[string]string) error { for key := range cfg { switch key { + case "labels": + case "env": default: return fmt.Errorf("unknown log opt '%s' for journald log driver", key) }