Documentation
¶
Overview ¶
Package kit provides a small adapter required to use go-kit/log in logging gRPC middlewares. Please see examples for examples of use.
Example (InitializationWithCodeGenRequestFieldExtractor) ¶
package main
import (
"github.com/go-kit/log"
"github.com/grpc-ecosystem/go-grpc-middleware/providers/kit/v2"
"google.golang.org/grpc"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
)
func main() {
// Logger is used, allowing pre-definition of certain fields by the user.
logger := log.NewNopLogger()
// Create a server, make sure we put the tags context before everything else.
_ = grpc.NewServer(
grpc.ChainUnaryInterceptor(
logging.UnaryServerInterceptor(kit.InterceptorLogger(logger)),
),
grpc.ChainStreamInterceptor(
logging.StreamServerInterceptor(kit.InterceptorLogger(logger)),
),
)
}
Output:
Example (InitializationWithCustomLevels) ¶
package main
import (
"github.com/go-kit/log"
"github.com/grpc-ecosystem/go-grpc-middleware/providers/kit/v2"
"google.golang.org/grpc"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
)
var customFunc logging.CodeToLevel
func main() {
// Logger is used, allowing pre-definition of certain fields by the user.
logger := log.NewNopLogger()
// Shared options for the logger, with a custom gRPC code to log level function.
opts := []logging.Option{
logging.WithLevels(customFunc),
}
// Create a server, make sure we put the tags context before everything else.
_ = grpc.NewServer(
grpc.ChainUnaryInterceptor(
logging.UnaryServerInterceptor(kit.InterceptorLogger(logger), opts...),
),
grpc.ChainStreamInterceptor(
logging.StreamServerInterceptor(kit.InterceptorLogger(logger), opts...),
),
)
}
Output:
Example (InitializationWithDurationFieldOverride) ¶
package main
import (
"github.com/go-kit/log"
"github.com/grpc-ecosystem/go-grpc-middleware/providers/kit/v2"
"google.golang.org/grpc"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
)
var customDurationToFields logging.DurationToFields
func main() {
// Logger is used, allowing pre-definition of certain fields by the user.
logger := log.NewNopLogger()
// Shared options for the logger, with a custom duration to log field function.
opts := []logging.Option{
logging.WithDurationField(customDurationToFields),
}
// Create a server, make sure we put the tags context before everything else.
_ = grpc.NewServer(
grpc.ChainUnaryInterceptor(
logging.UnaryServerInterceptor(kit.InterceptorLogger(logger), opts...),
),
grpc.ChainStreamInterceptor(
logging.StreamServerInterceptor(kit.InterceptorLogger(logger), opts...),
),
)
}
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
Click to show internal directories.
Click to hide internal directories.