1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

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 <dqminh@cloudflare.com>
This commit is contained in:
Daniel Dao 2015-10-04 21:06:19 +00:00 committed by Vincent Demeester
parent 4cc8490283
commit 11a24f19c2

View file

@ -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)
}