gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/go-grpc-middleware/logging/logrus/ctxlogrus/examples_test.go (about) 1 package ctxlogrus_test 2 3 import ( 4 "gitee.com/ks-custle/core-gm/go-grpc-middleware/logging/logrus/ctxlogrus" 5 grpcctxtags "gitee.com/ks-custle/core-gm/go-grpc-middleware/tags" 6 "gitee.com/ks-custle/core-gm/net/context" 7 "github.com/sirupsen/logrus" 8 ) 9 10 //goland:noinspection GoUnusedGlobalVariable 11 var logrusLogger *logrus.Logger 12 13 // Simple unary handler that adds custom fields to the requests's context. These will be used for all log statements. 14 func ExampleExtract_unary() { 15 ctx := context.Background() 16 // setting tags will be added to the logger as log fields 17 grpcctxtags.Extract(ctx).Set("custom_tags.string", "something").Set("custom_tags.int", 1337) 18 // Extract a single request-scoped logrus.Logger and log messages. 19 l := ctxlogrus.Extract(ctx) 20 l.Info("some ping") 21 l.Info("another ping") 22 }