Skip to content

Commit b96df77

Browse files
committed
Have daemon/logger.Context carry cgroup info
Make logger.Context into an object that also carries the cgroup path of the container for which it's logging, and initialize the field when we start a container. Signed-off-by: Nalin Dahyabhai <[email protected]>
1 parent 668e71a commit b96df77

File tree

6 files changed

+48
-3
lines changed

6 files changed

+48
-3
lines changed

container/container.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ func (container *Container) StartLogger(cfg containertypes.LogConfig) (logger.Lo
315315
if err != nil {
316316
return nil, fmt.Errorf("Failed to get logging factory: %v", err)
317317
}
318-
ctx := logger.Context{
318+
cctx := logger.CommonContext{
319319
Config: cfg.Config,
320320
ContainerID: container.ID,
321321
ContainerName: container.Name,
@@ -328,6 +328,7 @@ func (container *Container) StartLogger(cfg containertypes.LogConfig) (logger.Lo
328328
ContainerLabels: container.Config.Labels,
329329
DaemonName: "docker",
330330
}
331+
ctx := configurePlatformLogger(cctx, container)
331332

332333
// Set logging file for "json-logger"
333334
if cfg.Type == jsonfilelog.Name {

container/logger_linux.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package container
2+
3+
import (
4+
"github.com/docker/docker/daemon/logger"
5+
)
6+
7+
// configurePlatformLogger takes a logger.CommonContext and adds any
8+
// OS-specific information that is exclusive to a logger.Context.
9+
func configurePlatformLogger(ctx logger.CommonContext, container *Container) logger.Context {
10+
return logger.Context{
11+
CommonContext: ctx,
12+
ContainerCGroup: *container.Spec.Linux.CgroupsPath,
13+
}
14+
}

container/logger_notlinux.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// +build !linux
2+
3+
package container
4+
5+
// configurePlatformLogger takes a logger.CommonContext and adds any
6+
// OS-specific information that is exclusive to a logger.Context.
7+
func configurePlatformLogger(ctx logger.CommonContext, container *Container) logger.Context {
8+
return logger.Context(ctx)
9+
}

daemon/logger/context.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import (
77
"time"
88
)
99

10-
// Context provides enough information for a logging driver to do its function.
11-
type Context struct {
10+
// CommonContext provides almost enough information for a logging driver to do
11+
// its function, but not anything that's OS-specific.
12+
type CommonContext struct {
1213
Config map[string]string
1314
ContainerID string
1415
ContainerName string

daemon/logger/context_linux.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package logger
2+
3+
// Context provides enough information for a logging driver to do its function.
4+
type Context struct {
5+
// These fields are shared across all definitions.
6+
CommonContext
7+
// Fields below this point are platform-specific.
8+
ContainerCGroup string
9+
}
10+
11+
// CGroup returns the name of the container's cgroup.
12+
func (ctx *Context) CGroup() (string, error) {
13+
return ctx.ContainerCGroup, nil
14+
}

daemon/logger/context_notlinux.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// +build !linux
2+
3+
package logger
4+
5+
// Context provides enough information for a logging driver to do its function.
6+
type Context CommonContext

0 commit comments

Comments
 (0)