Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix loggers not respecting json config (#10808) #11655

Merged
merged 2 commits into from
Apr 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions lib/config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (
"time"
"unicode"

stdlog "log"

"golang.org/x/crypto/ssh"

"github.com/go-ldap/ldap/v3"
Expand Down Expand Up @@ -290,18 +292,10 @@ func ApplyFileConfig(fc *FileConfig, cfg *service.Config) error {
}

// apply logger settings
logger := utils.NewLogger()
err = applyLogConfig(fc.Logger, logger)
err = applyLogConfig(fc.Logger, cfg)
if err != nil {
return trace.Wrap(err)
}
cfg.Log = logger

// Apply logging configuration for the global logger instance
// DELETE this when global logger instance is no longer in use.
//
// Logging configuration has already been validated above
_ = applyLogConfig(fc.Logger, log.StandardLogger())

if fc.CachePolicy.TTL != "" {
log.Warn("cache.ttl config option is deprecated and will be ignored, caches no longer attempt to anticipate resource expiration.")
Expand Down Expand Up @@ -433,14 +427,18 @@ func ApplyFileConfig(fc *FileConfig, cfg *service.Config) error {
return nil
}

func applyLogConfig(loggerConfig Log, logger *log.Logger) error {
func applyLogConfig(loggerConfig Log, cfg *service.Config) error {
logger := log.StandardLogger()

switch loggerConfig.Output {
case "":
break // not set
case "stderr", "error", "2":
logger.SetOutput(os.Stderr)
cfg.Console = io.Discard // disable console printing
case "stdout", "out", "1":
logger.SetOutput(os.Stdout)
cfg.Console = io.Discard // disable console printing
case teleport.Syslog:
err := utils.SwitchLoggerToSyslog(logger)
if err != nil {
Expand Down Expand Up @@ -493,10 +491,13 @@ func applyLogConfig(loggerConfig Log, logger *log.Logger) error {
}

logger.SetFormatter(formatter)
stdlog.SetOutput(io.Discard) // disable the standard logger used by external dependencies
stdlog.SetFlags(0)
default:
return trace.BadParameter("unsupported log output format : %q", loggerConfig.Format.Output)
}

cfg.Log = logger
return nil
}

Expand Down