Documentation ¶
Index ¶
- Variables
- func GetRawJSON(i interface{}) *bytes.Buffer
- func GrpcLogSetNewZeroLogger()
- func GrpcLogSetZeroLogger(logger GrpcZeroLogger)
- func LogDuration(logger *zerolog.Event, t time.Time)
- func LogIP(ctx context.Context, logger *zerolog.Event)
- func LogIncomingCall(ctx context.Context, logger *zerolog.Event, method string, t time.Time, ...)
- func LogIncomingMetadata(ctx context.Context, e *zerolog.Event)
- func LogMetadata(md *metadata.MD) *zerolog.Event
- func LogMethod(logger *zerolog.Event, method string)
- func LogRequest(e *zerolog.Event, req interface{})
- func LogResponse(e *zerolog.Event, resp interface{})
- func LogService(logger *zerolog.Event, method string)
- func LogStatusError(logger *zerolog.Event, err error)
- func LogTimestamp(logger *zerolog.Event, t time.Time)
- func LogUserAgent(logger *zerolog.Event, md *metadata.MD)
- func NewUnaryServerInterceptor() grpc.UnaryServerInterceptor
- func NewUnaryServerInterceptorWithLogger(log *zerolog.Logger) grpc.UnaryServerInterceptor
- func UnaryInterceptor() grpc.ServerOption
- func UnaryInterceptorWithLogger(log *zerolog.Logger) grpc.ServerOption
- type GrpcZeroLogger
- func (l GrpcZeroLogger) Error(args ...interface{})
- func (l GrpcZeroLogger) Errorf(format string, args ...interface{})
- func (l GrpcZeroLogger) Errorln(args ...interface{})
- func (l GrpcZeroLogger) Fatal(args ...interface{})
- func (l GrpcZeroLogger) Fatalf(format string, args ...interface{})
- func (l GrpcZeroLogger) Fatalln(args ...interface{})
- func (l GrpcZeroLogger) Info(args ...interface{})
- func (l GrpcZeroLogger) Infof(format string, args ...interface{})
- func (l GrpcZeroLogger) Infoln(args ...interface{})
- func (l GrpcZeroLogger) Print(args ...interface{})
- func (l GrpcZeroLogger) Printf(format string, args ...interface{})
- func (l GrpcZeroLogger) Println(args ...interface{})
- func (l GrpcZeroLogger) V(level int) bool
- func (l GrpcZeroLogger) Warning(args ...interface{})
- func (l GrpcZeroLogger) Warningf(format string, args ...interface{})
- func (l GrpcZeroLogger) Warningln(args ...interface{})
Constants ¶
This section is empty.
Variables ¶
var ( // Marshaller of Protobuf to JSON Marshaller = &jsonpb.Marshaler{} // TimestampLog call start. TimestampLog = true // ServiceField key. ServiceField = "service" // ServiceLog gRPC service name. ServiceLog = true // MethodField key. MethodField = "method" // MethodLog gRPC method name. MethodLog = true // DurationField key. DurationField = "dur" // DurationLog gRPC call duration. DurationLog = true // IPField key. IPField = "ip" // IPLog gRPC client IP. IPLog = true // MetadataField key. MetadataField = "md" // MetadataLog gRPC call metadata. MetadataLog = true // UserAgentField key. UserAgentField = "ua" // UserAgentLog gRPC client User Agent. UserAgentLog = true // ReqField key. ReqField = "req" // ReqLog gRPC request body. ReqLog = true // RespField key. RespField = "resp" // RespLog gRPC response body. RespLog = true // MaxSize to log gRPC bodies. MaxSize = 2048000 // CodeField gRPC status code response. CodeField = "code" // MsgField gRPC response message. MsgField = "msg" // DetailsField gRPC response errors. DetailsField = "details" // UnaryMessageDefault of logging messages from unary. UnaryMessageDefault = "unary" )
Functions ¶
func GetRawJSON ¶
GetRawJSON converts a Protobuf message to JSON bytes if less than MaxSize.
func GrpcLogSetNewZeroLogger ¶
func GrpcLogSetNewZeroLogger()
GrpcLogSetNewZeroLogger sets grpclog to a new GrpcZeroLogger.
func GrpcLogSetZeroLogger ¶
func GrpcLogSetZeroLogger(logger GrpcZeroLogger)
GrpcLogSetZeroLogger sets grpclog to a GrpcZeroLogger.
func LogIncomingCall ¶
func LogIncomingCall(ctx context.Context, logger *zerolog.Event, method string, t time.Time, req interface{})
LogIncomingCall of gRPC method.
{ ServiceField: ExampleService, MethodField: ExampleMethod, DurationField: 1.00, }
func LogIncomingMetadata ¶
LogIncomingMetadata or UserAgent field of incoming gRPC Request, if assigned.
{ MetadataField: { MetadataKey1: MetadataValue1, } } { UserAgentField: "Client-assigned User-Agent", }
func LogRequest ¶
LogRequest in JSON of gRPC Call, given Request is smaller than MaxSize (Default=2MB).
{ ReqField: {} }
func LogResponse ¶
LogResponse in JSON of gRPC Call, given Response is smaller than MaxSize (Default=2MB).
{ RespField: {} }
func LogStatusError ¶
LogStatusError of gRPC Error Response.
{ Err: "An unexpected error occurred", CodeField: "Unknown", MsgField: "Error message returned from the server", DetailsField: [Errors], }
func LogUserAgent ¶
LogUserAgent of gRPC Client, if assigned.
{ UserAgentField: "Client-assigned User-Agent", }
func NewUnaryServerInterceptor ¶
func NewUnaryServerInterceptor() grpc.UnaryServerInterceptor
NewUnaryServerInterceptor that logs gRPC Requests using Zerolog.
{ ServiceField: "ExampleService", MethodField: "ExampleMethod", DurationField: 1.00 IpField: "127.0.0.1", MetadataField: {}, UserAgentField: "ExampleClientUserAgent", ReqField: {}, // JSON representation of Request Protobuf Err: "An unexpected error occurred", CodeField: "Unknown", MsgField: "Error message returned from the server", DetailsField: [Errors], RespField: {}, // JSON representation of Response Protobuf ZerologMessageField: "UnaryMessageDefault", }
func NewUnaryServerInterceptorWithLogger ¶
func NewUnaryServerInterceptorWithLogger(log *zerolog.Logger) grpc.UnaryServerInterceptor
func UnaryInterceptor ¶
func UnaryInterceptor() grpc.ServerOption
UnaryInterceptor is a gRPC Server Option that uses NewUnaryServerInterceptor() to log gRPC Requests.
func UnaryInterceptorWithLogger ¶
func UnaryInterceptorWithLogger(log *zerolog.Logger) grpc.ServerOption
Types ¶
type GrpcZeroLogger ¶
type GrpcZeroLogger struct {
// contains filtered or unexported fields
}
GrpcZeroLogger transforms grpc log calls to Zerolog logger.
func NewGrpcZeroLogger ¶
func NewGrpcZeroLogger(logger zerolog.Logger) GrpcZeroLogger
NewGrpcZeroLogger creates a new GrpcZeroLogger
func (GrpcZeroLogger) Error ¶
func (l GrpcZeroLogger) Error(args ...interface{})
Error errors arguments.
func (GrpcZeroLogger) Errorf ¶
func (l GrpcZeroLogger) Errorf(format string, args ...interface{})
Errorf errors formatted string with arguments.
func (GrpcZeroLogger) Errorln ¶
func (l GrpcZeroLogger) Errorln(args ...interface{})
Errorln errors and new line.
func (GrpcZeroLogger) Fatal ¶
func (l GrpcZeroLogger) Fatal(args ...interface{})
Fatal fatals arguments.
func (GrpcZeroLogger) Fatalf ¶
func (l GrpcZeroLogger) Fatalf(format string, args ...interface{})
Fatalf fatals formatted string with arguments.
func (GrpcZeroLogger) Fatalln ¶
func (l GrpcZeroLogger) Fatalln(args ...interface{})
Fatalln fatals and new line.
func (GrpcZeroLogger) Info ¶
func (l GrpcZeroLogger) Info(args ...interface{})
Info infos arguments.
func (GrpcZeroLogger) Infof ¶
func (l GrpcZeroLogger) Infof(format string, args ...interface{})
Infof infos formatted string with arguments.
func (GrpcZeroLogger) Infoln ¶
func (l GrpcZeroLogger) Infoln(args ...interface{})
Infoln infos and new line.
func (GrpcZeroLogger) Print ¶
func (l GrpcZeroLogger) Print(args ...interface{})
Print logs arguments.
func (GrpcZeroLogger) Printf ¶
func (l GrpcZeroLogger) Printf(format string, args ...interface{})
Printf logs formatted string with arguments.
func (GrpcZeroLogger) Println ¶
func (l GrpcZeroLogger) Println(args ...interface{})
Println logs with new line.
func (GrpcZeroLogger) Warning ¶
func (l GrpcZeroLogger) Warning(args ...interface{})
Warning warns arguments.
func (GrpcZeroLogger) Warningf ¶
func (l GrpcZeroLogger) Warningf(format string, args ...interface{})
Warningf warns formatted string with arguments.
func (GrpcZeroLogger) Warningln ¶
func (l GrpcZeroLogger) Warningln(args ...interface{})
Warningln warns and new line.