-
-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: upgrade grpc middleware to v2 (#1496)
- Loading branch information
Showing
4 changed files
with
47 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// 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) | ||
} | ||
}) | ||
} |