logging

package
v0.19.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2021 License: Apache-2.0 Imports: 7 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.

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 DefaultErrorToCode

func DefaultErrorToCode(_ error) int

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.

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() Decision

Decider function defines rules for suppressing the logging. TODO : Add the method name as a parameter in case we want to log based on method names.

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() Decision

DefaultDeciderMethod is the default implementation of decider to see if you should log the call by default this is set to LogStartAndFinishCall.

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 HTTPServerMiddleware

type HTTPServerMiddleware struct {
	// contains filtered or unexported fields
}

func NewHTTPServerMiddleware

func NewHTTPServerMiddleware(logger log.Logger, opts ...Option) *HTTPServerMiddleware

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 WithDecider

func WithDecider(f Decider) Option

WithDecider customizes the function for deciding if the HTTP Middlewares/Tripperwares should log.

func WithLevels

func WithLevels(f CodeToLevel) Option

WithLevels customizes the function for mapping HTTP response codes and interceptor log level statements.

Jump to

Keyboard shortcuts

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