Containerd Setting
# less /etc/containerd/config.toml
...
[debug]
address = ""
uid = 0
gid = 0
level = "info"
...
Kata Setting
借助于Package logrus is a structured logger for Go: ““github.com/sirupsen/logrus””
Example01
//首先定义shimLog
// shimLog is logger for shim package
var shimLog = logrus.WithFields(logrus.Fields{
"source": "containerd-kata-shim-v2",
"name": "containerd-shim-v2",
})
func create(ctx context.Context, s *service, r *taskAPI.CreateTaskRequest) (*container, error) {
...
switch containerType {
case vc.PodSandbox:
shimLog.WithField("ContainerType", vc.PodSandbox).Warn("Debug-Pod-Sandbox")
if s.sandbox != nil {
return nil, fmt.Errorf("cannot create another sandbox in sandbox: %s", s.sandbox.ID())
}
s.config, err = loadRuntimeConfig(s, r, ociSpec.Annotations)
if err != nil {
return nil, err
}
...
}
}
...
Example02
# 首先实现Container对应的Logger()方法
// Logger returns a logrus logger appropriate for logging Container messages
func (c *Container) Logger() *logrus.Entry {
return virtLog.WithFields(logrus.Fields{
"subsystem": "container",
"sandbox": c.sandboxID,
})
}
// create creates and starts a container inside a Sandbox. It has to be
// called only when a new container, not known by the sandbox, has to be created.
func (c *Container) create(ctx context.Context) (err error) {
...
if len(normalAttachedDevs) > 0 {
//在这里进行调用
c.Logger().WithField("normalAttachedDevs", normalAttachedDevs).Warn("normalAttachedDevs")
if err = c.attachDevices(ctx, normalAttachedDevs); err != nil {
return
}
}
...
}