Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultCodeToLevel(logger log.Logger, code int) log.Logger
- func DefaultErrorToCode(_ error) int
- func NewLogger(logLevel, logFormat, debugName string) log.Logger
- type CodeToLevel
- type Decider
- type Decision
- type DurationToFields
- type ErrorToCode
- type Fields
- type HTTPServerMiddleware
- type Option
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.
Functions ¶
func DefaultCodeToLevel ¶
DefaultCodeToLevel is the helper mapper that maps HTTP Response codes to log levels.
func DefaultErrorToCode ¶
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.
Types ¶
type CodeToLevel ¶
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.
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 ¶
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 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 ¶
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.