Documentation
¶
Overview ¶
Example (Initialization) ¶
Initialization shows a relatively complex initialization sequence.
package main import ( "github.com/go-kit/kit/log" middleware "github.com/grpc-ecosystem/go-grpc-middleware" "github.com/grpc-ecosystem/go-grpc-middleware/interceptors/logging" "github.com/grpc-ecosystem/go-grpc-middleware/interceptors/tags" "github.com/grpc-ecosystem/go-grpc-middleware/providers/kit" "google.golang.org/grpc" ) 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( middleware.WithUnaryServerChain( tags.UnaryServerInterceptor(tags.WithFieldExtractor(tags.CodeGenRequestFieldExtractor)), logging.UnaryServerInterceptor(kit.InterceptorLogger(logger), opts...), ), middleware.WithStreamServerChain( tags.StreamServerInterceptor(tags.WithFieldExtractor(tags.CodeGenRequestFieldExtractor)), logging.StreamServerInterceptor(kit.InterceptorLogger(logger), opts...), ), ) }
Output:
Example (InitializationWithDurationFieldOverride) ¶
package main import ( "github.com/go-kit/kit/log" middleware "github.com/grpc-ecosystem/go-grpc-middleware" "github.com/grpc-ecosystem/go-grpc-middleware/interceptors/logging" "github.com/grpc-ecosystem/go-grpc-middleware/interceptors/tags" "github.com/grpc-ecosystem/go-grpc-middleware/providers/kit" "google.golang.org/grpc" ) 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( middleware.WithUnaryServerChain( tags.UnaryServerInterceptor(), logging.UnaryServerInterceptor(kit.InterceptorLogger(logger), opts...), ), middleware.WithStreamServerChain( tags.StreamServerInterceptor(), 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.