Merge pull request #46525 from thaJeztah/daemon_typed_logformat
daemon: strongly type containerd log.OutputFormat
This commit is contained in:
commit
90b756b2a1
4 changed files with 16 additions and 12 deletions
|
@ -516,7 +516,7 @@ func loadDaemonCliConfig(opts *daemonOptions) (*config.Config, error) {
|
|||
conf.Debug = opts.Debug
|
||||
conf.Hosts = opts.Hosts
|
||||
conf.LogLevel = opts.LogLevel
|
||||
conf.LogFormat = opts.LogFormat
|
||||
conf.LogFormat = log.OutputFormat(opts.LogFormat)
|
||||
|
||||
if flags.Changed(FlagTLS) {
|
||||
conf.TLS = &opts.TLS
|
||||
|
@ -914,7 +914,7 @@ func systemContainerdRunning(honorXDG bool) (string, bool, error) {
|
|||
// configureDaemonLogs sets the logging level and formatting. It expects
|
||||
// the passed configuration to already be validated, and ignores invalid options.
|
||||
func configureDaemonLogs(conf *config.Config) {
|
||||
switch log.OutputFormat(conf.LogFormat) {
|
||||
switch conf.LogFormat {
|
||||
case log.JSONFormat:
|
||||
if err := log.SetFormat(log.JSONFormat); err != nil {
|
||||
panic(err.Error())
|
||||
|
|
|
@ -164,7 +164,7 @@ func TestLoadDaemonCliConfigWithLogFormat(t *testing.T) {
|
|||
loadedConfig, err := loadDaemonCliConfig(opts)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, loadedConfig != nil)
|
||||
assert.Check(t, is.Equal(log.JSONFormat, log.OutputFormat(loadedConfig.LogFormat)))
|
||||
assert.Check(t, is.Equal(log.JSONFormat, loadedConfig.LogFormat))
|
||||
}
|
||||
|
||||
func TestLoadDaemonCliConfigWithInvalidLogFormat(t *testing.T) {
|
||||
|
|
|
@ -180,12 +180,12 @@ type CommonConfig struct {
|
|||
// to stop when daemon is being shutdown
|
||||
ShutdownTimeout int `json:"shutdown-timeout,omitempty"`
|
||||
|
||||
Debug bool `json:"debug,omitempty"`
|
||||
Hosts []string `json:"hosts,omitempty"`
|
||||
LogLevel string `json:"log-level,omitempty"`
|
||||
LogFormat string `json:"log-format,omitempty"`
|
||||
TLS *bool `json:"tls,omitempty"`
|
||||
TLSVerify *bool `json:"tlsverify,omitempty"`
|
||||
Debug bool `json:"debug,omitempty"`
|
||||
Hosts []string `json:"hosts,omitempty"`
|
||||
LogLevel string `json:"log-level,omitempty"`
|
||||
LogFormat log.OutputFormat `json:"log-format,omitempty"`
|
||||
TLS *bool `json:"tls,omitempty"`
|
||||
TLSVerify *bool `json:"tlsverify,omitempty"`
|
||||
|
||||
// Embedded structs that allow config
|
||||
// deserialization without the full struct.
|
||||
|
@ -597,7 +597,7 @@ func Validate(config *Config) error {
|
|||
|
||||
// validate log-format
|
||||
if logFormat := config.LogFormat; logFormat != "" {
|
||||
switch log.OutputFormat(logFormat) {
|
||||
switch logFormat {
|
||||
case log.TextFormat, log.JSONFormat:
|
||||
// These are valid
|
||||
default:
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package supervisor // import "github.com/docker/docker/libcontainerd/supervisor"
|
||||
|
||||
import (
|
||||
"github.com/containerd/containerd/log"
|
||||
)
|
||||
|
||||
// WithLogLevel defines which log level to start containerd with.
|
||||
func WithLogLevel(lvl string) DaemonOpt {
|
||||
return func(r *remote) error {
|
||||
|
@ -15,9 +19,9 @@ func WithLogLevel(lvl string) DaemonOpt {
|
|||
|
||||
// WithLogFormat defines the containerd log format.
|
||||
// This only makes sense if WithStartDaemon() was set to true.
|
||||
func WithLogFormat(format string) DaemonOpt {
|
||||
func WithLogFormat(format log.OutputFormat) DaemonOpt {
|
||||
return func(r *remote) error {
|
||||
r.Debug.Format = format
|
||||
r.Debug.Format = string(format)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue