diff --git a/logger.go b/logger.go index 129703c..7df5368 100644 --- a/logger.go +++ b/logger.go @@ -27,16 +27,18 @@ func Logger() Option { if err != nil { logLevel = logrus.InfoLevel } + + s.logger = logrus.New() // set global log level - logrus.SetLevel(logLevel) + s.logger.SetLevel(logLevel) - logrus.SetFormatter(&logrus.TextFormatter{ + s.logger.SetFormatter(&logrus.TextFormatter{ FullTimestamp: true, DisableQuote: true, }) - logrus.SetReportCaller(true) - logrus.SetOutput(io.Discard) - logrus.AddHook(&writer.Hook{ + s.logger.SetReportCaller(true) + s.logger.SetOutput(io.Discard) + s.logger.AddHook(&writer.Hook{ Writer: os.Stderr, LogLevels: []logrus.Level{ logrus.PanicLevel, @@ -45,7 +47,7 @@ func Logger() Option { logrus.WarnLevel, }, }) - logrus.AddHook(&writer.Hook{ + s.logger.AddHook(&writer.Hook{ Writer: os.Stdout, LogLevels: []logrus.Level{ logrus.InfoLevel, @@ -54,12 +56,11 @@ func Logger() Option { }, }) - s.logLevel = &logLevel } } func (s *Service) L() *logrus.Entry { - return logrus.New().WithField("service", s.Name()) + return s.logger.WithField("service", s.Name()) } func GetLoggingOptions() []logging.Option { diff --git a/logger_test.go b/logger_test.go index 2d6cd8a..d1fcd4b 100644 --- a/logger_test.go +++ b/logger_test.go @@ -9,9 +9,10 @@ import ( func TestLogs(t *testing.T) { _, srv := frame.NewService("Logger Srv", frame.Config( - &frame.ConfigurationDefault{Oauth2WellKnownJwk: sampleWellKnownJwk})) + &frame.ConfigurationDefault{LogLevel: "Debug", Oauth2WellKnownJwk: sampleWellKnownJwk})) logger := srv.L() + logger.Debug("testing debug logs") logger.Info("testing logs") err := errors.New("") diff --git a/service.go b/service.go index 31b3ef5..b7bc0ed 100644 --- a/service.go +++ b/service.go @@ -42,7 +42,7 @@ type Service struct { jwtClientSecret string version string environment string - logLevel *logrus.Level + logger *logrus.Logger traceExporter trace.SpanExporter traceSampler trace.Sampler handler http.Handler