forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
container_logger.go
50 lines (43 loc) · 1.44 KB
/
container_logger.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package mgr
import (
"github.com/alibaba/pouch/apis/types"
"github.com/alibaba/pouch/daemon/containerio"
"github.com/alibaba/pouch/daemon/logger"
"github.com/sirupsen/logrus"
)
func logOptionsForContainerio(c *Container) []func(*containerio.Option) {
optFuncs := make([]func(*containerio.Option), 0, 1)
cfg := c.HostConfig.LogConfig
if cfg == nil || cfg.LogDriver == types.LogConfigLogDriverNone {
return optFuncs
}
switch cfg.LogDriver {
case types.LogConfigLogDriverJSONFile:
optFuncs = append(optFuncs, containerio.WithJSONFile())
case types.LogConfigLogDriverSyslog:
optFuncs = append(optFuncs, containerio.WithSyslog())
default:
logrus.Warnf("not support (%v) log driver yet", cfg.LogDriver)
}
return optFuncs
}
// convContainerToLoggerInfo uses logger.Info to wrap container information.
func (mgr *ContainerManager) convContainerToLoggerInfo(c *Container) logger.Info {
logCfg := make(map[string]string)
if cfg := c.HostConfig.LogConfig; cfg != nil && cfg.LogDriver != types.LogConfigLogDriverNone {
logCfg = cfg.LogOpts
}
// TODO(fuwei):
// 1. add more fields into logger.Info
// 2. separate the logic about retrieving container root dir from mgr.
return logger.Info{
LogConfig: logCfg,
ContainerID: c.ID,
ContainerName: c.Name,
ContainerImageID: c.Image,
ContainerLabels: c.Config.Labels,
ContainerEnvs: c.Config.Env,
ContainerRootDir: mgr.Store.Path(c.ID),
DaemonName: "pouchd",
}
}