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:
parent
4cc8490283
commit
11a24f19c2
1 changed files with 10 additions and 1 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue