Documentation ¶
Index ¶
- Constants
- func Annotator(ctx context.Context, req *http.Request) metadata.MD
- func CopyLoggerWithLevel(logger *logrus.Logger, lvl logrus.Level) *logrus.Logger
- func CustomFieldsStreamServerInterceptor(entry *logrus.Entry, opts ...Option) grpc.StreamServerInterceptor
- func CustomFieldsUnaryServerInterceptor(entry *logrus.Entry, opts ...Option) grpc.UnaryServerInterceptor
- func DisableRequestID(o *gwLogCfg)
- func EnableAccountID(o *gwLogCfg)
- func EnableDynamicLogLevel(o *gwLogCfg)
- func GatewayLoggingInterceptor(logger *logrus.Logger, opts ...GWLogOption) grpc.UnaryClientInterceptor
- func GatewayLoggingSentinelInterceptor() grpc.UnaryClientInterceptor
- func LogLevelInterceptor(defaultLevel logrus.Level) grpc.UnaryServerInterceptor
- func New(level string) *logrus.Logger
- func SentinelValueFromCtx(ctx context.Context) (value, ok bool)
- func StreamClientInterceptor(entry *logrus.Entry, opts ...Option) grpc.StreamClientInterceptor
- func StreamServerInterceptor(entry *logrus.Entry, opts ...Option) grpc.StreamServerInterceptor
- func UnaryClientInterceptor(entry *logrus.Entry, opts ...Option) grpc.UnaryClientInterceptor
- func UnaryServerInterceptor(entry *logrus.Entry, opts ...Option) grpc.UnaryServerInterceptor
- type CodeToLevel
- type GWLogOption
- type Option
Constants ¶
const ( DefaultAccountIDKey = "account_id" DefaultRequestIDKey = "request_id" DefaultSubjectKey = "subject" // Might be used for different purposes DefaultDurationKey = "grpc.time_ms" DefaultGRPCCodeKey = "grpc.code" DefaultGRPCMethodKey = "grpc.method" DefaultGRPCServiceKey = "grpc.service" DefaultGRPCStartTimeKey = "grpc.start_time" DefaultClientKindValue = "client" DefaultServerKindValue = "server" )
Variables ¶
This section is empty.
Functions ¶
func Annotator ¶
Annotator is a function that reads the http headers of incoming requests searching for special logging arguments
func CopyLoggerWithLevel ¶
CopyLoggerWithLevel makes a copy of the given (logrus) logger at the logger level. If copying an entry, use CopyLoggerWithLevel(entry.Logger, level).WithFields(entry.Data) on the result (changes to these entries' fields will not affect each other).
func CustomFieldsStreamServerInterceptor ¶
func CustomFieldsStreamServerInterceptor(entry *logrus.Entry, opts ...Option) grpc.StreamServerInterceptor
func CustomFieldsUnaryServerInterceptor ¶
func CustomFieldsUnaryServerInterceptor(entry *logrus.Entry, opts ...Option) grpc.UnaryServerInterceptor
func DisableRequestID ¶
func DisableRequestID(o *gwLogCfg)
DisableRequestID disables request-id inclusion (and generation if needed) in gw interceptor logs
func EnableAccountID ¶
func EnableAccountID(o *gwLogCfg)
EnableAccountID is a shorthand for WithAccountID(nil)
func EnableDynamicLogLevel ¶
func EnableDynamicLogLevel(o *gwLogCfg)
EnableDynamicLogLevel is a shorthand for WithDynamicLogLevel(true)
func GatewayLoggingInterceptor ¶
func GatewayLoggingInterceptor(logger *logrus.Logger, opts ...GWLogOption) grpc.UnaryClientInterceptor
GatewayLoggingInterceptor handles the functions of the various toolkit interceptors offered for the grpc server, as well as the standard grpc_logrus server interceptor behavior (superset of grpc_logrus client interceptor behavior)
func GatewayLoggingSentinelInterceptor ¶
func GatewayLoggingSentinelInterceptor() grpc.UnaryClientInterceptor
GatewayLoggingSentinelInterceptor is meant to be the last interceptor in the client interceptor chain, it sets a value left in the context by the GatewayLoggingInterceptor so that it knows whether the call makes it to the server, and thus the server will log the call, and the gateway doesn't need to.
func LogLevelInterceptor ¶
func LogLevelInterceptor(defaultLevel logrus.Level) grpc.UnaryServerInterceptor
LogLevelInterceptor sets the level of the logger in the context to either the default or the value set in the context via grpc metadata. Also sets the custom log tag if present for pseudo-tracing purposes
func SentinelValueFromCtx ¶
func StreamClientInterceptor ¶
func StreamClientInterceptor(entry *logrus.Entry, opts ...Option) grpc.StreamClientInterceptor
func StreamServerInterceptor ¶
func StreamServerInterceptor(entry *logrus.Entry, opts ...Option) grpc.StreamServerInterceptor
func UnaryClientInterceptor ¶
func UnaryClientInterceptor(entry *logrus.Entry, opts ...Option) grpc.UnaryClientInterceptor
func UnaryServerInterceptor ¶
func UnaryServerInterceptor(entry *logrus.Entry, opts ...Option) grpc.UnaryServerInterceptor
Types ¶
type CodeToLevel ¶
CodeToLevel function defines the mapping between gRPC return codes and interceptor log level. From https://github.com/grpc-ecosystem/go-grpc-middleware/blob/06f64829ca1f521d41cd6235a7a204a6566fb0dc/logging/logrus/options.go#L57
type GWLogOption ¶
type GWLogOption func(*gwLogCfg)
GWLogOption is a type of function that alters a gwLogCfg in the instantiation of a GatewayLoggingInterceptor
func WithAccountID ¶
func WithAccountID(keyfunc jwt.Keyfunc) GWLogOption
WithAccountID enables the account_id field in gw interceptor logs, like the server interceptor
func WithCodeFunc ¶
func WithCodeFunc(codeFunc grpc_logrus.CodeToLevel) GWLogOption
func WithDynamicLogLevel ¶
func WithDynamicLogLevel(enable bool) GWLogOption
WithDynamicLogLevel enables or disables dynamic log levels like handled in the server interceptor
type Option ¶
type Option func(*options)
func WithCustomFields ¶
Allows to provide custom fields for logging which are expected to be in JWT token
func WithCustomHeaders ¶
Allows to provide custom fields for logging from request headers
func WithLevels ¶
func WithLevels(f CodeToLevel) Option
WithLevels customizes the function for mapping gRPC return codes and interceptor log level statements. From https://github.com/grpc-ecosystem/go-grpc-middleware/blob/06f64829ca1f521d41cd6235a7a204a6566fb0dc/logging/logrus/options.go#L70