Documentation ¶
Index ¶
- Constants
- func Configure(out io.Writer, format string, level string, hooks ...logrus.Hook) logrus.FieldLogger
- func DeciderOption() grpcmwlogrus.Option
- func Default() *logrus.Entry
- func InitContextCustomFields(ctx context.Context) context.Context
- func MessageProducer(mp grpcmwlogrus.MessageProducer, fieldsProducers ...FieldsProducer) grpcmwlogrus.MessageProducer
- func PropagationMessageProducer(actual grpcmwlogrus.MessageProducer) grpcmwlogrus.MessageProducer
- func StreamLogDataCatcherServerInterceptor() grpc.StreamServerInterceptor
- func UTCJsonFormatter() logrus.Formatter
- func UTCTextFormatter() logrus.Formatter
- func UnaryLogDataCatcherServerInterceptor() grpc.UnaryServerInterceptor
- type Config
- type CustomFields
- type FieldsProducer
- type PerRPCLogHandler
- func (lh PerRPCLogHandler) HandleConn(ctx context.Context, cs stats.ConnStats)
- func (lh PerRPCLogHandler) HandleRPC(ctx context.Context, rs stats.RPCStats)
- func (lh PerRPCLogHandler) TagConn(ctx context.Context, cti *stats.ConnTagInfo) context.Context
- func (lh PerRPCLogHandler) TagRPC(ctx context.Context, rti *stats.RPCTagInfo) context.Context
- type URLSanitizerHook
Constants ¶
const ( // GitalyLogDirEnvKey defines the environment variable used to specify the Gitaly log directory GitalyLogDirEnvKey = "GITALY_LOG_DIR" // LogTimestampFormat defines the timestamp format in log files LogTimestampFormat = "2006-01-02T15:04:05.000" // LogTimestampFormatUTC defines the utc timestamp format in log files LogTimestampFormatUTC = "2006-01-02T15:04:05.000Z" )
Variables ¶
This section is empty.
Functions ¶
func Configure ¶
Configure configures the default and gRPC loggers. The gRPC logger's log level will be mapped in order to decrease its default verbosity. Returns the configured default logger that would also be returned by `Default()`.
func DeciderOption ¶
func DeciderOption() grpcmwlogrus.Option
DeciderOption returns a Option to support log filtering. If "GITALY_LOG_REQUEST_METHOD_DENY_PATTERN" ENV variable is set, logger will filter out the log whose "fullMethodName" matches it; If "GITALY_LOG_REQUEST_METHOD_ALLOW_PATTERN" ENV variable is set, logger will only keep the log whose "fullMethodName" matches it; Under any conditions, the error log will not be filtered out; If the ENV variables are not set, there will be no additional effects.
func InitContextCustomFields ¶ added in v16.2.0
InitContextCustomFields returns a new context with `CustomFields` added to the given context.
func MessageProducer ¶
func MessageProducer(mp grpcmwlogrus.MessageProducer, fieldsProducers ...FieldsProducer) grpcmwlogrus.MessageProducer
MessageProducer returns a wrapper that extends passed mp to accept additional fields generated by each of the fieldsProducers.
func PropagationMessageProducer ¶
func PropagationMessageProducer(actual grpcmwlogrus.MessageProducer) grpcmwlogrus.MessageProducer
PropagationMessageProducer catches logging information from the context and populates it to the special holder that should be present in the context. Should be used only in combination with PerRPCLogHandler.
func StreamLogDataCatcherServerInterceptor ¶
func StreamLogDataCatcherServerInterceptor() grpc.StreamServerInterceptor
StreamLogDataCatcherServerInterceptor catches logging data produced by the upper interceptors and propagates it into the holder to pop up it to the HandleRPC method of the PerRPCLogHandler.
func UTCJsonFormatter ¶
UTCJsonFormatter returns a Formatter that formats a logrus Entry's as json and converts the time field into UTC
func UTCTextFormatter ¶
UTCTextFormatter returns a Formatter that formats a logrus Entry's as text and converts the time field into UTC
func UnaryLogDataCatcherServerInterceptor ¶
func UnaryLogDataCatcherServerInterceptor() grpc.UnaryServerInterceptor
UnaryLogDataCatcherServerInterceptor catches logging data produced by the upper interceptors and propagates it into the holder to pop up it to the HandleRPC method of the PerRPCLogHandler.
Types ¶
type Config ¶ added in v16.3.0
type Config struct { Dir string `toml:"dir,omitempty" json:"dir"` Format string `toml:"format,omitempty" json:"format"` Level string `toml:"level,omitempty" json:"level"` }
Config contains logging configuration values
type CustomFields ¶ added in v16.2.0
CustomFields stores custom fields, which will be logged as a part of gRPC logs. The gRPC server is expected to add corresponding interceptors. They initialize a CustomFields object and inject it into the context. Callers can pull the object out with CustomFieldsFromContext.
func CustomFieldsFromContext ¶ added in v16.2.0
func CustomFieldsFromContext(ctx context.Context) *CustomFields
CustomFieldsFromContext gets the `CustomFields` from the given context.
func (*CustomFields) Fields ¶ added in v16.2.0
func (fields *CustomFields) Fields() logrus.Fields
Fields returns all the fields as logrus.Fields
func (*CustomFields) RecordMax ¶ added in v16.2.0
func (fields *CustomFields) RecordMax(key string, value int)
RecordMax will store the max value for a given key.
func (*CustomFields) RecordMetadata ¶ added in v16.2.0
func (fields *CustomFields) RecordMetadata(key string, value any)
RecordMetadata records a string metadata for the given key.
func (*CustomFields) RecordSum ¶ added in v16.2.0
func (fields *CustomFields) RecordSum(key string, value int)
RecordSum sums up all the values for a given key.
type FieldsProducer ¶
FieldsProducer returns fields that need to be added into the logging context. error argument is the result of RPC handling.
type PerRPCLogHandler ¶
type PerRPCLogHandler struct { Underlying stats.Handler FieldProducers []FieldsProducer }
PerRPCLogHandler is designed to collect stats that are accessible from the google.golang.org/grpc/stats.Handler, because some information can't be extracted on the interceptors level.
func (PerRPCLogHandler) HandleConn ¶
func (lh PerRPCLogHandler) HandleConn(ctx context.Context, cs stats.ConnStats)
HandleConn only calls Underlying and exists to satisfy gRPC stats.Handler.
func (PerRPCLogHandler) HandleRPC ¶
func (lh PerRPCLogHandler) HandleRPC(ctx context.Context, rs stats.RPCStats)
HandleRPC catches each RPC call and for the *stats.End stats invokes custom message producers to populate logging data. Once all data is collected the actual logging happens by using logger that is caught by PropagationMessageProducer.
func (PerRPCLogHandler) TagConn ¶
func (lh PerRPCLogHandler) TagConn(ctx context.Context, cti *stats.ConnTagInfo) context.Context
TagConn only calls Underlying and exists to satisfy gRPC stats.Handler.
func (PerRPCLogHandler) TagRPC ¶
func (lh PerRPCLogHandler) TagRPC(ctx context.Context, rti *stats.RPCTagInfo) context.Context
TagRPC propagates a special data holder into the context that is responsible to hold logging information produced by the logging interceptor. The logging data should be caught by the UnaryLogDataCatcherServerInterceptor. It needs to be included into the interceptor chain below logging interceptor.
type URLSanitizerHook ¶ added in v16.3.0
type URLSanitizerHook struct {
// contains filtered or unexported fields
}
URLSanitizerHook stores which gRPC methods to perform sanitization for.
func NewURLSanitizerHook ¶ added in v16.3.0
func NewURLSanitizerHook() *URLSanitizerHook
NewURLSanitizerHook returns a new logrus hook for sanitizing URLs.
func (*URLSanitizerHook) AddPossibleGrpcMethod ¶ added in v16.3.0
func (hook *URLSanitizerHook) AddPossibleGrpcMethod(methods ...string)
AddPossibleGrpcMethod adds method names that we should sanitize URLs from their logs.
func (*URLSanitizerHook) Fire ¶ added in v16.3.0
func (hook *URLSanitizerHook) Fire(entry *logrus.Entry) error
Fire is called by logrus.
func (*URLSanitizerHook) Levels ¶ added in v16.3.0
func (hook *URLSanitizerHook) Levels() []logrus.Level
Levels is called by logrus.