From ae951cf834c344475d24460ada912cb012917568 Mon Sep 17 00:00:00 2001 From: Joseph Arrieta Date: Mon, 30 Mar 2020 15:31:41 -0500 Subject: [PATCH] Improve logging configuration (#91) * Improve logging configuration * Fix linter issues --- tools/logger.go | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/tools/logger.go b/tools/logger.go index 94f6472..9c27579 100644 --- a/tools/logger.go +++ b/tools/logger.go @@ -6,18 +6,35 @@ import ( ) // For more information: https://github.com/sirupsen/logrus/blob/master/example_basic_test.go +// If we want to use a specific logging service there +// are multiple formatters implementations here: https://github.com/sirupsen/logrus#formatters var log *logrus.Logger //nolint func InitializeLogger() { - log = logrus.New() - log.SetLevel(logrus.TraceLevel) - - if os.Getenv("AUTH_SERVER_APP_ENV") == "production" { - log.SetLevel(logrus.InfoLevel) + if isProduction() { + initializeLoggerForProduction() + } else { + initializeLogger() } +} + +func isProduction() bool { + return os.Getenv("AUTH_SERVER_APP_ENV") == "production" +} + +func initializeLoggerForProduction() { + initializeLogger() + log.Level = logrus.InfoLevel + log.SetReportCaller(false) +} - log.SetOutput(os.Stdout) +func initializeLogger() { + log = logrus.New() + log.Formatter = &logrus.TextFormatter{FullTimestamp: true} + log.SetReportCaller(true) + log.Level = logrus.TraceLevel + log.Out = os.Stdout } func Log() *logrus.Logger {