Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultCodeToLevel(logger log.Logger, code int) log.Logger
- func DefaultCodeToLevelGRPC(c codes.Code) grpc_logging.Level
- func DefaultErrorToCode(_ error) int
- func DefaultFilterLogging(logger log.Logger) log.Logger
- func NewGRPCOption(configYAML []byte) ([]tags.Option, []grpc_logging.Option, error)
- func NewLogger(logLevel, logFormat, debugName string) log.Logger
- func ParsegRPCOptions(flagDecision string, reqLogConfig *extflag.PathOrContent) ([]tags.Option, []grpc_logging.Option, error)
- type CodeToLevel
- type Decider
- type Decision
- type DecisionConfig
- type DurationToFields
- type ErrorToCode
- type Fields
- type FilterLogging
- type GRPCProtocolConfig
- type GRPCProtocolConfigs
- type HTTPProtocolConfig
- type HTTPProtocolConfigs
- type HTTPServerMiddleware
- type Option
- type OptionsConfig
- type RequestConfig
Constants ¶
const ( LogFormatLogfmt = "logfmt" LogFormatJSON = "json" )
Variables ¶
var LogDecision = map[string]Decision{ "NoLogCall": NoLogCall, "LogFinishCall": LogFinishCall, "LogStartAndFinishCall": LogStartAndFinishCall, }
LogDecision defines mapping of flag options to the logging decision.
var MapAllowedLevels = map[string][]string{
"DEBUG": {"INFO", "DEBUG", "WARN", "ERROR"},
"ERROR": {"ERROR"},
"INFO": {"INFO", "WARN", "ERROR"},
"WARN": {"WARN", "ERROR"},
}
MapAllowedLevels allows to map a given level to a list of allowed level. Convention taken from go-kit/level v0.10.0 https://godoc.org/github.com/go-kit/log/level#AllowAll.
Functions ¶
func DefaultCodeToLevel ¶
DefaultCodeToLevel is the helper mapper that maps HTTP Response codes to log levels.
func DefaultCodeToLevelGRPC ¶ added in v0.20.0
func DefaultCodeToLevelGRPC(c codes.Code) grpc_logging.Level
DefaultCodeToLevelGRPC is the helper mapper that maps gRPC Response codes to log levels.
func DefaultErrorToCode ¶
DefaultErrorToCode returns an InternalServerError.
func DefaultFilterLogging ¶ added in v0.20.0
DefaultFilterLogging allows logs from all levels to be logged in output.
func NewGRPCOption ¶ added in v0.20.0
NewGRPCOption adds in the config options and returns tags for logging middleware.
func NewLogger ¶ added in v0.17.0
NewLogger returns a log.Logger that prints in the provided format at the provided level with a UTC timestamp and the caller of the log entry. If non empty, the debug name is also appended as a field to all log lines. Panics if the log level is not error, warn, info or debug. Log level is expected to be validated before passed to this function.
func ParsegRPCOptions ¶ added in v0.20.0
func ParsegRPCOptions(flagDecision string, reqLogConfig *extflag.PathOrContent) ([]tags.Option, []grpc_logging.Option, error)
TODO: @yashrsharma44 - To be deprecated in the next release.
Types ¶
type CodeToLevel ¶
CodeToLevel function defines the mapping between HTTP Response codes to log levels for server side.
type Decision ¶
type Decision int
Decision defines rules for enabling start and end of logging.
func DefaultDeciderMethod ¶
DefaultDeciderMethod is the default implementation of decider to see if you should log the call by default this is set to LogStartAndFinishCall.
type DecisionConfig ¶ added in v0.20.0
type DurationToFields ¶
DurationToFields function defines how to produce duration fields for logging.
type ErrorToCode ¶
ErrorToCode function determines the error code of the error for the http response.
type Fields ¶
type Fields []string
Fields represents logging fields. It has to have even number of elements (pairs).
func DurationToTimeMillisFields ¶
DurationToTimeMillisFields converts the duration to milliseconds and uses the key `http.time_ms`.
type FilterLogging ¶ added in v0.20.0
FilterLogging makes sure only the logs with level=lvl gets logged, or filtered.
type GRPCProtocolConfig ¶ added in v0.20.0
type GRPCProtocolConfigs ¶ added in v0.20.0
type GRPCProtocolConfigs struct { Options OptionsConfig `yaml:"options"` Config []GRPCProtocolConfig `yaml:"config"` }
type HTTPProtocolConfig ¶ added in v0.20.0
type HTTPProtocolConfigs ¶ added in v0.20.0
type HTTPProtocolConfigs struct { Options OptionsConfig `yaml:"options"` Config []HTTPProtocolConfig `yaml:"config"` }
type HTTPServerMiddleware ¶
type HTTPServerMiddleware struct {
// contains filtered or unexported fields
}
func NewHTTPServerMiddleware ¶
func NewHTTPServerMiddleware(logger log.Logger, opts ...Option) *HTTPServerMiddleware
NewHTTPServerMiddleware returns an http middleware.
func (*HTTPServerMiddleware) HTTPMiddleware ¶
func (m *HTTPServerMiddleware) HTTPMiddleware(name string, next http.Handler) http.HandlerFunc
type Option ¶
type Option func(*options)
Types for the Options.
func NewHTTPOption ¶ added in v0.20.0
NewHTTPOption returns a http config option.
func ParseHTTPOptions ¶ added in v0.20.0
func ParseHTTPOptions(flagDecision string, reqLogConfig *extflag.PathOrContent) ([]Option, error)
TODO: @yashrsharma44 - To be deprecated in the next release.
func WithDecider ¶
WithDecider customizes the function for deciding if the HTTP Middlewares/Tripperwares should log.
func WithFilter ¶ added in v0.20.0
func WithFilter(f FilterLogging) Option
WithFilter customizes the function for deciding which level of logging should be allowed. Follows go-kit Allow<level of log> convention.
func WithLevels ¶
func WithLevels(f CodeToLevel) Option
WithLevels customizes the function for mapping HTTP response codes and interceptor log level statements.
type OptionsConfig ¶ added in v0.20.0
type OptionsConfig struct { Level string `yaml:"level"` Decision DecisionConfig `yaml:"decision"` }
type RequestConfig ¶ added in v0.20.0
type RequestConfig struct { HTTP HTTPProtocolConfigs `yaml:"http"` GRPC GRPCProtocolConfigs `yaml:"grpc"` Options OptionsConfig `yaml:"options"` }
func NewRequestConfig ¶ added in v0.20.0
func NewRequestConfig(configYAML []byte) (*RequestConfig, error)
NewRequestConfig parses the string into a req logging config structure. Raise an error if unmarshalling is not possible, or values are not valid.