logger

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: MIT Imports: 13 Imported by: 23

Documentation

Overview

Package logger implements logging middleware

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnonymizeIP added in v1.5.4

func AnonymizeIP(ip string) string

AnonymizeIP is a function to reset the last part of IPv4 to 0. from 123.212.12.78 it will make 123.212.12.0

func ApacheCombined added in v1.5.4

func ApacheCombined(l *Middleware)

ApacheCombined sets format to Apache Combined Log. See http://httpd.apache.org/docs/2.2/logs.html#combined

func Logger added in v1.1.2

func Logger(next http.Handler) http.Handler

Logger is a default logger middleware with "REST" prefix

func WithBody added in v1.4.0

func WithBody(l *Middleware)

WithBody triggers request body logging. Body size is limited (default 1k)

Types

type Backend added in v1.2.0

type Backend interface {
	Logf(format string, args ...interface{})
}

Backend is logging backend

type Middleware

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

Middleware is a logger for rest requests.

func New

func New(options ...Option) *Middleware

New makes rest logger with given options

func (*Middleware) Handler

func (l *Middleware) Handler(next http.Handler) http.Handler

Handler middleware prints http log

type Option

type Option func(l *Middleware)

Option func type

func IPfn

func IPfn(ipFn func(ip string) string) Option

IPfn sets IP masking function. If ipFn is nil then IP address will be logged as is.

func Log added in v1.1.6

func Log(log Backend) Option

Log sets logging backend.

func MaxBodySize

func MaxBodySize(max int) Option

MaxBodySize sets size of the logged part of the request body.

func Prefix

func Prefix(prefix string) Option

Prefix sets log line prefix.

func SubjFn added in v1.3.0

func SubjFn(subjFn func(r *http.Request) (string, error)) Option

SubjFn triggers subject logging if subjFn is not nil.

func UserFn

func UserFn(userFn func(r *http.Request) (string, error)) Option

UserFn triggers user name logging if userFn is not nil.

Jump to

Keyboard shortcuts

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