Logging

    gRPC server

    By passing in grpc.ServerOption, Kratos will print detailed request information every time a gRPC request is received.

    gRPC client

    1. logger := log.DefaultLogger
    2. var opts = []http.ServerOption{
    3. http.Middleware(
    4. logging.Server(logger),
    5. ),
    6. }

    HTTP client

    By passing logging.Client() in http.WithMiddleware, Kratos will print detailed request information every time an Http request is initiated.

    grpc-server

    1. // internal/server/grpc.go
    2. exporter, err := stdouttrace.New(stdouttrace.WithWriter(ioutil.Discard))
    3. if err != nil {
    4. fmt.Printf("creating stdout exporter: %v", err)
    5. panic(err)
    6. }
    7. tp := tracesdk.NewTracerProvider(
    8. tracesdk.WithBatcher(exporter),
    9. tracesdk.WithResource(resource.NewSchemaless(
    10. )
    11. var opts = []grpc.ServerOption{
    12. grpc.Middleware(
    13. tracing.Server(tracing.WithTracerProvider(tp)),
    14. ),
    15. }
    16. srv := grpc.NewServer(opts...)

    Add the trace_id field to the output log

    1. log.WithContext(ctx).Errorf("Field created: %s", err)