diff --git a/cmd/containerd/main.go b/cmd/containerd/main.go index a066b9062..6fd022068 100644 --- a/cmd/containerd/main.go +++ b/cmd/containerd/main.go @@ -54,7 +54,7 @@ func main() { }, cli.StringFlag{ Name: "log-level,l", - Usage: "set the logging level [debug, info, warn, error, fatal, panic]", + Usage: "set the logging level [trace, debug, info, warn, error, fatal, panic]", }, cli.StringFlag{ Name: "address,a", @@ -192,7 +192,7 @@ func setLevel(context *cli.Context, config *server.Config) error { l = config.Debug.Level } if l != "" { - lvl, err := logrus.ParseLevel(l) + lvl, err := log.ParseLevel(l) if err != nil { return err } diff --git a/log/context.go b/log/context.go index 471c35270..48af28744 100644 --- a/log/context.go +++ b/log/context.go @@ -21,6 +21,19 @@ type ( loggerKey struct{} ) +// TraceLevel is the log level for tracing. Trace level is lower than debug level, +// and is usually used to trace detailed behavior of the program. +const TraceLevel = logrus.Level(uint32(logrus.DebugLevel + 1)) + +// ParseLevel takes a string level and returns the Logrus log level constant. +// It supports trace level. +func ParseLevel(lvl string) (logrus.Level, error) { + if lvl == "trace" { + return TraceLevel, nil + } + return logrus.ParseLevel(lvl) +} + // WithLogger returns a new context with the provided logger. Use in // combination with logger.WithField(s) for great effect. func WithLogger(ctx context.Context, logger *logrus.Entry) context.Context { @@ -38,3 +51,17 @@ func GetLogger(ctx context.Context) *logrus.Entry { return logger.(*logrus.Entry) } + +// Trace logs a message at level Trace with the log entry passed-in. +func Trace(e *logrus.Entry, args ...interface{}) { + if e.Level >= TraceLevel { + e.Debug(args...) + } +} + +// Tracef logs a message at level Trace with the log entry passed-in. +func Tracef(e *logrus.Entry, format string, args ...interface{}) { + if e.Level >= TraceLevel { + e.Debugf(format, args...) + } +}