Skip to content

Commit

Permalink
fix loggers not respecting json config (#10808)
Browse files Browse the repository at this point in the history
  • Loading branch information
NajiObeid authored Mar 18, 2022
1 parent 2cb0b66 commit 16bf416
Showing 1 changed file with 11 additions and 10 deletions.
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 @@ -289,18 +291,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.Warnf("cache.ttl config option is deprecated and will be ignored, caches no longer attempt to anticipate resource expiration.")
Expand Down Expand Up @@ -427,14 +421,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 @@ -487,10 +485,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

0 comments on commit 16bf416

Please sign in to comment.