Remove most logrus

Signed-off-by: Jin Dong <jin.dong@databricks.com>
This commit is contained in:
Jin Dong
2023-08-26 13:17:03 -04:00
parent 03e4f1e363
commit fc45365fa1
31 changed files with 84 additions and 94 deletions

View File

@@ -24,10 +24,10 @@ import (
"time"
"github.com/containerd/containerd"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/runtime/restart"
"github.com/sirupsen/logrus"
)
type duration struct {
@@ -92,7 +92,7 @@ func (m *monitor) run(interval time.Duration) {
}
for {
if err := m.reconcile(context.Background()); err != nil {
logrus.WithError(err).Error("reconcile")
log.L.WithError(err).Error("reconcile")
}
time.Sleep(interval)
}
@@ -112,7 +112,7 @@ func (m *monitor) reconcile(ctx context.Context) error {
ctx := namespaces.WithNamespace(ctx, name)
changes, err := m.monitor(ctx)
if err != nil {
logrus.WithError(err).Error("monitor for changes")
log.G(ctx).WithError(err).Error("monitor for changes")
return
}
var wgChangesLoop sync.WaitGroup
@@ -122,7 +122,7 @@ func (m *monitor) reconcile(ctx context.Context) error {
go func() {
defer wgChangesLoop.Done()
if err := c.apply(ctx, m.client); err != nil {
logrus.WithError(err).Error("apply change")
log.G(ctx).WithError(err).Error("apply change")
}
}()
}
@@ -160,7 +160,7 @@ func (m *monitor) monitor(ctx context.Context) ([]change, error) {
// Task or Status return error, only desired to running
if err != nil {
logrus.WithError(err).Error("monitor")
log.G(ctx).WithError(err).Error("monitor")
if desiredStatus == containerd.Stopped {
continue
}
@@ -182,7 +182,7 @@ func (m *monitor) monitor(ctx context.Context) ([]change, error) {
restartCount, _ := strconv.Atoi(labels[restart.CountLabel])
if labels["containerd.io/restart.logpath"] != "" {
logrus.Warn(`Label "containerd.io/restart.logpath" is no longer supported since containerd v2.0. Use "containerd.io/restart.loguri" instead.`)
log.G(ctx).Warn(`Label "containerd.io/restart.logpath" is no longer supported since containerd v2.0. Use "containerd.io/restart.loguri" instead.`)
}
changes = append(changes, &startChange{
container: c,

View File

@@ -39,7 +39,7 @@ import (
"github.com/containerd/containerd"
"github.com/containerd/containerd/cio"
"github.com/containerd/containerd/containers"
"github.com/sirupsen/logrus"
"github.com/containerd/containerd/log"
)
const (
@@ -119,7 +119,7 @@ func (rp *Policy) MaximumRetryCount() int {
func Reconcile(status containerd.Status, labels map[string]string) bool {
rp, err := NewPolicy(labels[PolicyLabel])
if err != nil {
logrus.WithError(err).Error("policy reconcile")
log.L.WithError(err).Error("policy reconcile")
return false
}
switch rp.Name() {
@@ -128,7 +128,7 @@ func Reconcile(status containerd.Status, labels map[string]string) bool {
case "on-failure":
restartCount, err := strconv.Atoi(labels[CountLabel])
if err != nil && labels[CountLabel] != "" {
logrus.WithError(err).Error("policy reconcile")
log.L.WithError(err).Error("policy reconcile")
return false
}
if status.ExitStatus != 0 && (rp.maximumRetryCount == 0 || restartCount < rp.maximumRetryCount) {

View File

@@ -167,7 +167,7 @@ func setLogger(ctx context.Context, id string) (context.Context, error) {
FullTimestamp: true,
})
if debugFlag {
l.Logger.SetLevel(logrus.DebugLevel)
l.Logger.SetLevel(log.DebugLevel)
}
f, err := openLog(ctx, id)
if err != nil {
@@ -235,13 +235,13 @@ func run(ctx context.Context, manager Manager, name string, config Config) error
// Handle explicit actions
switch action {
case "delete":
if debugFlag {
logrus.SetLevel(logrus.DebugLevel)
}
logger := log.G(ctx).WithFields(log.Fields{
"pid": os.Getpid(),
"namespace": namespaceFlag,
})
if debugFlag {
logger.Logger.SetLevel(log.DebugLevel)
}
go reap(ctx, logger, signals)
ss, err := manager.Stop(ctx, id)
if err != nil {
@@ -350,7 +350,7 @@ func run(ctx context.Context, manager Manager, name string, config Config) error
}
if src, ok := instance.(TTRPCService); ok {
logrus.WithField("id", id).Debug("registering ttrpc service")
log.G(ctx).WithField("id", id).Debug("registering ttrpc service")
ttrpcServices = append(ttrpcServices, src)
}
@@ -432,7 +432,7 @@ func serve(ctx context.Context, server *ttrpc.Server, signals chan os.Signal, sh
return reap(ctx, logger, signals)
}
func dumpStacks(logger *logrus.Entry) {
func dumpStacks(logger *log.Entry) {
var (
buf []byte
stackSize int

View File

@@ -27,6 +27,7 @@ import (
"os/signal"
"syscall"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/sys/reaper"
"github.com/containerd/fifo"
"github.com/sirupsen/logrus"
@@ -66,7 +67,7 @@ func serveListener(path string) (net.Listener, error) {
if err != nil {
return nil, err
}
logrus.WithField("socket", path).Debug("serving api on socket")
log.L.WithField("socket", path).Debug("serving api on socket")
return l, nil
}