reference global logrus (#274)

* reference logrus' global logger instead of passing and storing a logger reference everywhere

* always directly use global logrus logger instead of referencing an instance

* test suites should also directly use the global logrus logger

* rename gin logging function to clarify that it's middleware

* correct comments which erroneously referenced removed logger parameter

* setting log level for tests now uses logrus' exported type instead of the string value, to guarantee error isn't possible
This commit is contained in:
R. Aidan Campbell 2021-10-11 05:37:33 -07:00 committed by GitHub
commit 083099a957
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
210 changed files with 506 additions and 662 deletions

View file

@ -27,26 +27,24 @@ import (
"github.com/uptrace/bun"
)
func newDebugQueryHook(log *logrus.Logger) bun.QueryHook {
func newDebugQueryHook() bun.QueryHook {
return &debugQueryHook{
log: log,
}
}
// debugQueryHook implements bun.QueryHook
type debugQueryHook struct {
log *logrus.Logger
}
func (q *debugQueryHook) BeforeQuery(ctx context.Context, event *bun.QueryEvent) context.Context {
func (q *debugQueryHook) BeforeQuery(ctx context.Context, _ *bun.QueryEvent) context.Context {
// do nothing
return ctx
}
// AfterQuery logs the time taken to query, the operation (select, update, etc), and the query itself as translated by bun.
func (q *debugQueryHook) AfterQuery(ctx context.Context, event *bun.QueryEvent) {
func (q *debugQueryHook) AfterQuery(_ context.Context, event *bun.QueryEvent) {
dur := time.Since(event.StartTime).Round(time.Microsecond)
l := q.log.WithFields(logrus.Fields{
l := logrus.WithFields(logrus.Fields{
"duration": dur,
"operation": event.Operation(),
})