Log all errors regardless of log level (#496)

Modify the loggerDebug function to check whether the error is nil before
choosing the log level.

Fixes #473
This commit is contained in:
Zach Wasserman 2021-03-18 16:06:06 -07:00 committed by GitHub
parent 5c69094571
commit d827a9d6b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,9 +1,9 @@
package service
import (
"github.com/fleetdm/fleet/server/kolide"
kitlog "github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/fleetdm/fleet/server/kolide"
)
// logging middleware logs the service actions
@ -17,8 +17,11 @@ func NewLoggingService(svc kolide.Service, logger kitlog.Logger) kolide.Service
return loggingMiddleware{Service: svc, logger: logger}
}
// loggerDebug returns the debug level
// loggerDebug returns the the info level if there error is non-nil, otherwise defaulting to the debug level.
func (mw loggingMiddleware) loggerDebug(err error) kitlog.Logger {
if err != nil {
return level.Info(mw.logger)
}
return level.Debug(mw.logger)
}