slogger

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: LGPL-2.1 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RequestBodyMaxSize  = 64 * 1024 // 64KB
	ResponseBodyMaxSize = 64 * 1024 // 64KB

	HiddenRequestHeaders = map[string]struct{}{
		"authorization": {},
		"cookie":        {},
		"set-cookie":    {},
		"x-auth-token":  {},
		"x-csrf-token":  {},
		"x-xsrf-token":  {},
	}
	HiddenResponseHeaders = map[string]struct{}{
		"set-cookie": {},
	}
)

custom var

Functions

func AddCustomAttributes

func AddCustomAttributes(c echo.Context, attr slog.Attr)

AddCustomAttributes adds custom slog.Attr

func New

func New(logger *slog.Logger) echo.MiddlewareFunc

New returns a echo.MiddlewareFunc (middleware) that logs requests using slog.

Requests with errors are logged using slog.Error(). Requests without errors are logged using slog.Info().

func NewWithConfig

func NewWithConfig(logger *slog.Logger, config Config) echo.MiddlewareFunc

NewWithConfig returns a echo.HandlerFunc (middleware) that logs requests using slog.

func NewWithFilters

func NewWithFilters(logger *slog.Logger, filters ...Filter) echo.MiddlewareFunc

NewWithFilters returns a echo.MiddlewareFunc (middleware) that logs requests using slog.

Requests with errors are logged using slog.Error(). Requests without errors are logged using slog.Info().

Types

type Config

type Config struct {
	DefaultLevel     slog.Level
	ClientErrorLevel slog.Level
	ServerErrorLevel slog.Level

	WithUserAgent      bool
	WithRequestID      bool
	WithRequestBody    bool
	WithRequestHeader  bool
	WithResponseBody   bool
	WithResponseHeader bool
	WithSpanID         bool
	WithTraceID        bool

	Filters []Filter
}

Config provide configurations

type Filter

type Filter func(ctx echo.Context) bool

Filter is core filter

func AcceptHost

func AcceptHost(hosts ...string) Filter

AcceptHost filters allow by host

func AcceptHostContains

func AcceptHostContains(parts ...string) Filter

AcceptHostContains filters allow host contains

func AcceptHostMatch

func AcceptHostMatch(regs ...regexp.Regexp) Filter

AcceptHostMatch filter allow by host matched regex

func AcceptHostPrefix

func AcceptHostPrefix(prefixs ...string) Filter

AcceptHostPrefix filters allow host by prefix

func AcceptHostSuffix

func AcceptHostSuffix(prefixs ...string) Filter

AcceptHostSuffix filters allow by host suffix

func AcceptMethod

func AcceptMethod(methods ...string) Filter

AcceptMethod filters allow by method

func AcceptPath

func AcceptPath(urls ...string) Filter

AcceptPath filters allow by path

func AcceptPathContains

func AcceptPathContains(parts ...string) Filter

AcceptPathContains filters allow by path contains

func AcceptPathMatch

func AcceptPathMatch(regs ...regexp.Regexp) Filter

AcceptPathMatch filters allow by path matched regexp

func AcceptPathPrefix

func AcceptPathPrefix(prefixs ...string) Filter

AcceptPathPrefix filters allow by path prefix

func AcceptPathSuffix

func AcceptPathSuffix(prefixs ...string) Filter

AcceptPathSuffix filters allow by path suffix

func AcceptStatus

func AcceptStatus(statuses ...int) Filter

AcceptStatus filters allow by status

func AcceptStatusGreaterThan

func AcceptStatusGreaterThan(status int) Filter

AcceptStatusGreaterThan filters allow by status gt

func AcceptStatusGreaterThanOrEqual

func AcceptStatusGreaterThanOrEqual(status int) Filter

AcceptStatusGreaterThanOrEqual filters allow by status gte

func IgnoreHost

func IgnoreHost(hosts ...string) Filter

IgnoreHost filters disallow by host

func IgnoreHostContains

func IgnoreHostContains(parts ...string) Filter

IgnoreHostContains filters disallow host contains

func IgnoreHostMatch

func IgnoreHostMatch(regs ...regexp.Regexp) Filter

IgnoreHostMatch filter disallow by host matched regex

func IgnoreHostPrefix

func IgnoreHostPrefix(prefixs ...string) Filter

IgnoreHostPrefix filters disallow host by prefix

func IgnoreHostSuffix

func IgnoreHostSuffix(suffixs ...string) Filter

IgnoreHostSuffix filters disallow by host suffix

func IgnoreMethod

func IgnoreMethod(methods ...string) Filter

IgnoreMethod filters disallow by method

func IgnorePath

func IgnorePath(urls ...string) Filter

IgnorePath filters disallow by path

func IgnorePathContains

func IgnorePathContains(parts ...string) Filter

IgnorePathContains filters disallow by path contains

func IgnorePathMatch

func IgnorePathMatch(regs ...regexp.Regexp) Filter

IgnorePathMatch filters disallow by path matched regexp

func IgnorePathPrefix

func IgnorePathPrefix(prefixs ...string) Filter

IgnorePathPrefix filters disallow by path prefix

func IgnorePathSuffix

func IgnorePathSuffix(suffixs ...string) Filter

IgnorePathSuffix filters disallow by path suffix

func IgnoreStatus

func IgnoreStatus(statuses ...int) Filter

IgnoreStatus filters disallow by status

func IgnoreStatusLessThan

func IgnoreStatusLessThan(status int) Filter

IgnoreStatusLessThan filters disallow by status lt

func IgnoreStatusLessThanOrEqual

func IgnoreStatusLessThanOrEqual(status int) Filter

IgnoreStatusLessThanOrEqual filters disallow by status lte

Jump to

Keyboard shortcuts

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