diff --git a/cmd/containerd/command/main.go b/cmd/containerd/command/main.go index 922b54f8f..3b8e9739e 100644 --- a/cmd/containerd/command/main.go +++ b/cmd/containerd/command/main.go @@ -357,7 +357,7 @@ func setLogLevel(context *cli.Context, config *srvconfig.Config) error { } func setLogFormat(config *srvconfig.Config) error { - f := config.Debug.Format + f := log.OutputFormat(config.Debug.Format) if f == "" { f = log.TextFormat } diff --git a/log/context.go b/log/context.go index a6075a8ce..57aac5c7d 100644 --- a/log/context.go +++ b/log/context.go @@ -96,17 +96,20 @@ func GetLevel() Level { return logrus.GetLevel() } +// OutputFormat specifies a log output format. +type OutputFormat string + // Supported log output formats. const ( // TextFormat represents the text logging format. - TextFormat = "text" + TextFormat OutputFormat = "text" // JSONFormat represents the JSON logging format. - JSONFormat = "json" + JSONFormat OutputFormat = "json" ) // SetFormat sets the log output format ([TextFormat] or [JSONFormat]). -func SetFormat(format string) error { +func SetFormat(format OutputFormat) error { switch format { case TextFormat: logrus.SetFormatter(&logrus.TextFormatter{