Some checks failed
CI / Run lints and checks (push) Failing after 47s
CI / Run tests (push) Failing after 1s
CI / Run race tests (push) Failing after 5s
CI / Build CLI docs (push) Has been skipped
CI / Run buf actions (push) Failing after 5s
CodeQL / Analyze (go) (push) Failing after 3s
CodeQL / Analyze (javascript) (push) Failing after 2s
Docker Image Scanners / scanners (push) Failing after 3s
Format / format (push) Failing after 3s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Draft newsletter (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
41 lines
1011 B
Go
41 lines
1011 B
Go
// Copyright © 2023 Ory Corp
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package driver
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// InterceptorLogger adapts logrus logger to interceptor logger.
|
|
// This code is simple enough to be copied and not imported.
|
|
//
|
|
// Source from: https://github.com/grpc-ecosystem/go-grpc-middleware/blob/main/interceptors/logging/examples/logrus/example_test.go
|
|
func InterceptorLogger(l logrus.FieldLogger) logging.Logger {
|
|
return logging.LoggerFunc(func(_ context.Context, lvl logging.Level, msg string, fields ...any) {
|
|
f := make(map[string]any, len(fields)/2)
|
|
i := logging.Fields(fields).Iterator()
|
|
if i.Next() {
|
|
k, v := i.At()
|
|
f[k] = v
|
|
}
|
|
l := l.WithFields(f)
|
|
|
|
switch lvl {
|
|
case logging.LevelDebug:
|
|
l.Debug(msg)
|
|
case logging.LevelInfo:
|
|
l.Info(msg)
|
|
case logging.LevelWarn:
|
|
l.Warn(msg)
|
|
case logging.LevelError:
|
|
l.Error(msg)
|
|
default:
|
|
l.Info(msg)
|
|
}
|
|
})
|
|
}
|