// 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) } }) }