Skip to content

Commit

Permalink
std/grpc: Export SerializeMessage.
Browse files Browse the repository at this point in the history
Can be reused for Connect-Go.
  • Loading branch information
nichtverstehen committed Oct 10, 2023
1 parent 473a100 commit f52d530
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions std/grpc/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ func (interceptor) unary(ctx context.Context, req interface{}, info *grpc.UnaryS
loggable := !slices.Contains(skipLogging, strings.TrimPrefix(info.FullMethod, "/"))

if loggable {
makeNewEvent(ctx, logger.Info().Str("kind", "grpclog").Str("what", "request")).Str("request_body", serializeMessage(req)).Send()
makeNewEvent(ctx, logger.Info().Str("kind", "grpclog").Str("what", "request")).Str("request_body", SerializeMessage(req)).Send()
}

resp, err := handler(logger.WithContext(ctx), req)
if loggable {
if err == nil {
logger.Info().Str("kind", "grpclog").Dur("took", time.Since(rdata.Started)).Str("what", "response").Str("response_body", serializeMessage(resp)).Send()
logger.Info().Str("kind", "grpclog").Dur("took", time.Since(rdata.Started)).Str("what", "response").Str("response_body", SerializeMessage(resp)).Send()
} else {
logger.Info().Str("kind", "grpclog").Dur("took", time.Since(rdata.Started)).Str("what", "response").Err(err).Send()
}
Expand Down Expand Up @@ -193,7 +193,7 @@ func Prepare(ctx context.Context, deps ExtensionDeps) error {
return nil
}

func serializeMessage(msg interface{}) string {
func SerializeMessage(msg interface{}) string {
if msg == nil {
return "<nil>"
}
Expand Down

0 comments on commit f52d530

Please sign in to comment.