github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/go-grpc-middleware/logging/logrus/ctxlogrus/examples_test.go (about)

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