Skip to content

Config: Sanitize unexpectedly mutates custom logger #269

@iamcalledrob

Description

@iamcalledrob

The following code exists in config.go:

func (c *Config) Sanitize() error {
	if c.LogOutput == nil {
		c.LogOutput = os.Stderr
	}

	if c.LogLevel == "" {
		c.LogLevel = DefaultLogLevel
	}

	if c.LogVerbosity <= 0 {
		c.LogVerbosity = DefaultLogVerbosity
	}

	if c.Logger == nil {
		c.Logger = log.New(c.LogOutput, "", log.LstdFlags)
	} else {
		c.Logger.SetOutput(c.LogOutput) // <-- !
	}
        // ...

If you provide a custom logger, the else branch overrides that logger's output. That's very unexpected behaviour, as it is mutating the logger for all its users.

I think you can remove the else branch and things will work as expected?

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions