logging

package
v0.26.0-rc.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2022 License: Apache-2.0 Imports: 19 Imported by: 8

Documentation

Index

Constants

View Source
const (
	LogFormatLogfmt = "logfmt"
	LogFormatJSON   = "json"
)

Variables

View Source
var LogDecision = map[string]Decision{
	"NoLogCall":             NoLogCall,
	"LogFinishCall":         LogFinishCall,
	"LogStartAndFinishCall": LogStartAndFinishCall,
}

LogDecision defines mapping of flag options to the logging decision.

View Source
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 NewGRPCOption added in v0.20.0

func NewGRPCOption(configYAML []byte) ([]tags.Option, []grpc_logging.Option, error)

NewGRPCOption adds in the config options and returns tags 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(flagDecision string, reqLogConfig *extflag.PathOrContent) ([]tags.Option, []grpc_logging.Option, 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 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(flagDecision string, 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL