Skip to content

Commit

Permalink
Improve logging configuration (#91)
Browse files Browse the repository at this point in the history
* Improve logging configuration

* Fix linter issues
  • Loading branch information
jac1013 authored Mar 30, 2020
1 parent 874365e commit ae951cf
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions tools/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ae951cf

Please sign in to comment.