Skip to content

Commit

Permalink
gcp logging format
Browse files Browse the repository at this point in the history
  • Loading branch information
ferhatbostanci committed Jun 7, 2021
1 parent aa71c98 commit 4027cfc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/PulseyTeam/game-server
go 1.16

require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/rs/zerolog v1.22.0
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.7.0
Expand Down
5 changes: 2 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func main() {
zerolog.LevelFieldName = "severity"
zerolog.TimestampFieldName = "timestamp"
zerolog.TimeFieldFormat = time.RFC3339Nano
log.Logger = log.With().Logger()
} else {
consoleWriter := zerolog.ConsoleWriter{Out: os.Stderr}
consoleWriter.TimeFormat = time.RFC3339
Expand Down Expand Up @@ -72,7 +71,7 @@ func unaryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServ
now := time.Now()

defer func() {
log.Trace().Str("method", info.FullMethod).Msgf("request completed in %v", time.Since(now))
log.Trace().Str("requestUrl", info.FullMethod).Str("latency", fmt.Sprintf("%v", time.Since(now))).Msgf("request completed")
}()

return handler(ctx, req)
Expand All @@ -82,7 +81,7 @@ func streamInterceptor(srv interface{}, stream grpc.ServerStream, info *grpc.Str
now := time.Now()

defer func() {
log.Trace().Str("method", info.FullMethod).Msgf("stream completed in %v", time.Since(now))
log.Trace().Str("requestUrl", info.FullMethod).Str("latency", fmt.Sprintf("%v", time.Since(now))).Msgf("stream completed")
}()

return handler(srv, stream)
Expand Down

0 comments on commit 4027cfc

Please sign in to comment.