1 package ctxlogrus_test 2 3 import ( 4 "context" 5 6 "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" 7 "github.com/grpc-ecosystem/go-grpc-middleware/tags" 8 ) 9 10 // Simple unary handler that adds custom fields to the requests's context. These will be used for all log statements. 11 func ExampleExtract_unary() { 12 ctx := context.Background() 13 // setting tags will be added to the logger as log fields 14 grpc_ctxtags.Extract(ctx).Set("custom_tags.string", "something").Set("custom_tags.int", 1337) 15 // Extract a single request-scoped logrus.Logger and log messages. 16 l := ctxlogrus.Extract(ctx) 17 l.Info("some ping") 18 l.Info("another ping") 19 } 20