本文整理汇总了Golang中github.com/docker/docker/daemon/logger.Context.LogPath方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.LogPath方法的具体用法?Golang Context.LogPath怎么用?Golang Context.LogPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/docker/docker/daemon/logger.Context
的用法示例。
在下文中一共展示了Context.LogPath方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: initLogger
func (c *Container) initLogger() {
if c.logger.Driver != nil {
return
}
if c.p.factory.logCreator == nil {
return
}
ctx := logger.Context{
Config: c.p.factory.logCfg.Config,
ContainerID: c.Id(),
ContainerName: c.RuntimeName(),
ContainerImageName: c.descript.Image,
ContainerCreated: c.status.CreatedAt,
ContainerEntrypoint: c.descript.Path,
ContainerArgs: c.descript.Args,
ContainerImageID: c.descript.Image,
}
if c.p.factory.logCfg.Type == jsonfilelog.Name {
prefix := c.p.factory.logCfg.PathPrefix
if c.p.factory.logCfg.PodIdInPath {
prefix = filepath.Join(prefix, c.p.Id())
}
if err := os.MkdirAll(prefix, os.FileMode(0755)); err != nil {
c.Log(ERROR, "cannot create container log dir %s: %v", prefix, err)
return
}
ctx.LogPath = filepath.Join(prefix, fmt.Sprintf("%s-json.log", c.Id()))
c.Log(DEBUG, "configure container log to %s", ctx.LogPath)
}
driver, err := c.p.factory.logCreator(ctx)
if err != nil {
return
}
c.logger.Driver = driver
c.Log(DEBUG, "container logger configured")
return
}
示例2: getLogger
func (p *Pod) getLogger(daemon *Daemon) (err error) {
if p.spec.LogConfig.Type == "" {
p.spec.LogConfig.Type = daemon.DefaultLog.Type
p.spec.LogConfig.Config = daemon.DefaultLog.Config
}
if p.spec.LogConfig.Type == "none" {
return nil
}
var (
needLogger []int = []int{}
creator logger.Creator
)
for i, c := range p.status.Containers {
if c.Logs.Driver == nil {
needLogger = append(needLogger, i)
}
}
if len(needLogger) == 0 && p.status.Status == types.S_POD_RUNNING {
return nil
}
if err = logger.ValidateLogOpts(p.spec.LogConfig.Type, p.spec.LogConfig.Config); err != nil {
return
}
creator, err = logger.GetLogDriver(p.spec.LogConfig.Type)
if err != nil {
return
}
glog.V(1).Infof("configuring log driver [%s] for %s", p.spec.LogConfig.Type, p.id)
for i, c := range p.status.Containers {
ctx := logger.Context{
Config: p.spec.LogConfig.Config,
ContainerID: c.Id,
ContainerName: c.Name,
ContainerImageName: p.spec.Containers[i].Image,
ContainerCreated: time.Now(), //FIXME: should record creation time in PodStatus
}
if p.containers != nil && len(p.containers) > i {
ctx.ContainerEntrypoint = p.containers[i].Workdir
ctx.ContainerArgs = p.containers[i].Cmd
ctx.ContainerImageID = p.containers[i].Image
}
if p.spec.LogConfig.Type == jsonfilelog.Name {
ctx.LogPath = filepath.Join(p.status.ResourcePath, fmt.Sprintf("%s-json.log", c.Id))
glog.V(1).Info("configure container log to ", ctx.LogPath)
}
if c.Logs.Driver, err = creator(ctx); err != nil {
return
}
glog.V(1).Infof("configured logger for %s/%s (%s)", p.id, c.Id, c.Name)
}
return nil
}