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 GetTraceIDAndRequestIDAsField(ctx context.Context) grpc_logging.Fields
- func InterceptorLogger(l log.Logger) grpc_logging.Logger
- func NewGRPCOption(configYAML []byte) ([]grpc_logging.Option, []string, error)
- func NewLogger(logLevel, logFormat, debugName string) log.Logger
- func ParsegRPCOptions(reqLogConfig *extflag.PathOrContent) ([]grpc_logging.Option, []string, 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 LevelLogger
- type Option
- type OptionsConfig
- type RequestConfig
- type ResponseWriterWithStatus
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 ¶
func DefaultCodeToLevel(logger log.Logger, code int) log.Logger
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 ¶
func DefaultErrorToCode(_ error) int
DefaultErrorToCode returns an InternalServerError.
func DefaultFilterLogging ¶ added in v0.20.0
func DefaultFilterLogging(logger log.Logger) log.Logger
DefaultFilterLogging allows logs from all levels to be logged in output.
func GetTraceIDAndRequestIDAsField ¶ added in v0.36.0
func GetTraceIDAndRequestIDAsField(ctx context.Context) grpc_logging.Fields
func InterceptorLogger ¶ added in v0.36.0
func InterceptorLogger(l log.Logger) grpc_logging.Logger
func NewGRPCOption ¶ added in v0.20.0
func NewGRPCOption(configYAML []byte) ([]grpc_logging.Option, []string, error)
NewGRPCOption adds in the config options for logging middleware.
func NewLogger ¶ added in v0.17.0
func NewLogger(logLevel, logFormat, debugName string) log.Logger
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(reqLogConfig *extflag.PathOrContent) ([]grpc_logging.Option, []string, error)
TODO: @yashrsharma44 - To be deprecated in the next release.
Types ¶
type CodeToLevel ¶
type CodeToLevel func(logger log.Logger, code int) log.Logger
CodeToLevel function defines the mapping between HTTP Response codes to log levels for server side.
type Decider ¶
type Decider func(methodName string, err error) Decision
Decider function defines rules for suppressing the logging.
type Decision ¶
type Decision int
Decision defines rules for enabling start and end of logging.
const (
// NoLogCall - Logging is disabled.
NoLogCall Decision = iota
// LogFinishCall - Only finish logs of request is enabled.
LogFinishCall
// LogStartAndFinishCall - Logging of start and end of request is enabled.
LogStartAndFinishCall
)
func DefaultDeciderMethod ¶
func DefaultDeciderMethod(_ string, _ error) Decision
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 DecisionConfig struct {
LogStart bool `yaml:"log_start"`
LogEnd bool `yaml:"log_end"`
}
type DurationToFields ¶
type DurationToFields func(duration time.Duration) Fields
DurationToFields function defines how to produce duration fields for logging.
type ErrorToCode ¶
type ErrorToCode func(err error) int
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 ¶
func DurationToTimeMillisFields(duration time.Duration) Fields
DurationToTimeMillisFields converts the duration to milliseconds and uses the key `http.time_ms`.
type FilterLogging ¶ added in v0.20.0
type FilterLogging func(logger log.Logger) log.Logger
FilterLogging makes sure only the logs with level=lvl gets logged, or filtered.
type GRPCProtocolConfig ¶ added in v0.20.0
type GRPCProtocolConfig struct {
Service string `yaml:"service"`
Method string `yaml:"method"`
}
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 HTTPProtocolConfig struct {
Path string `yaml:"path"`
Port uint64 `yaml:"port"`
}
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 LevelLogger ¶ added in v0.38.0
type LevelLogger struct {
log.Logger
LogLevel string
}
type Option ¶
type Option func(*options)
Types for the Options.
func NewHTTPOption ¶ added in v0.20.0
func NewHTTPOption(configYAML []byte) ([]Option, error)
NewHTTPOption returns a http config option.
func ParseHTTPOptions ¶ added in v0.20.0
func ParseHTTPOptions(reqLogConfig *extflag.PathOrContent) ([]Option, error)
TODO: @yashrsharma44 - To be deprecated in the next release.
func WithDecider ¶
func WithDecider(f Decider) Option
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.
type ResponseWriterWithStatus ¶ added in v0.38.0
type ResponseWriterWithStatus struct {
http.ResponseWriter
// contains filtered or unexported fields
}
ResponseWriterWithStatus wraps around http.ResponseWriter to capture the status code of the response.
func WrapResponseWriterWithStatus ¶ added in v0.38.0
func WrapResponseWriterWithStatus(w http.ResponseWriter) *ResponseWriterWithStatus
WrapResponseWriterWithStatus wraps the http.ResponseWriter for extracting status.
func (*ResponseWriterWithStatus) Status ¶ added in v0.38.0
func (r *ResponseWriterWithStatus) Status() int
Status returns http response status.
func (*ResponseWriterWithStatus) WriteHeader ¶ added in v0.38.0
func (r *ResponseWriterWithStatus) WriteHeader(code int)
WriteHeader writes the header.