From 16bf416556f337b045b66dc9c3f5a3e16f8cc988 Mon Sep 17 00:00:00 2001 From: NajiObeid Date: Fri, 18 Mar 2022 00:36:06 -0400 Subject: [PATCH] fix loggers not respecting json config (#10808) --- lib/config/configuration.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/config/configuration.go b/lib/config/configuration.go index de1ed39f0d043..de9c06fdf5473 100644 --- a/lib/config/configuration.go +++ b/lib/config/configuration.go @@ -34,6 +34,8 @@ import ( "time" "unicode" + stdlog "log" + "golang.org/x/crypto/ssh" "github.com/go-ldap/ldap/v3" @@ -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.") @@ -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 { @@ -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 }