accesslog

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: BSD-3-Clause Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const Message string = "access request"

Variables

This section is empty.

Functions

func IgnoreHandler added in v0.3.0

func IgnoreHandler(next http.Handler) http.Handler

IgnoreHandler returns a http.Handler that marks the http.Request as "should ignore".

func Middleware

func Middleware(log Logger, next http.Handler) http.Handler

Middleware wraps a http.Handler so it's request and response details are tracked and send to Logger log.

func RemoteAddr

func RemoteAddr(r *http.Request) string

RemoteAddr returns a sanitized remote address from the http.Request.

func SetShouldIgnore added in v0.2.0

func SetShouldIgnore(ctx context.Context, ignore bool) bool

SetShouldIgnore marks the context from a http.Request as "should ignore". It return true if the context was successfully updated. If the context does not already contain a reference to

func ShouldIgnore added in v0.2.0

func ShouldIgnore(ctx context.Context) bool

ShouldIgnore returns if the http.Request's context contains a "should ignore" value set using SetShouldIgnore.

func Username

func Username(r *http.Request) string

Types

type Details

type Details struct {
	ServerName  string
	HandlerName string
	UserAgent   string

	// StatusCode is the first http response code passed to the
	// [http.ResponseWriter.WriteHeader]. See [httpsnoop.Metrics] for additional
	// information.
	StatusCode int
	// StartTime is the time the request was received.
	StartTime time.Time
	// Duration is the time it took to execute the handler.
	Duration time.Duration
	// BytesWritten is the number of bytes successfully written by the
	// [http.ResponseWriter.Write] or [http.ResponseWriter.ReadFrom] functions.
	// See [httpsnoop.Metrics] for additional information.
	BytesWritten int64
	// RequestCount is the amount of open requests during the execution of the
	// handler.
	RequestCount int64
}

Details are collected with Middleware and contain additional details of a request and it's corresponding response.

type Logger

type Logger interface {
	Log(ctx context.Context, det Details, req *http.Request)
}

func DefaultLogger

func DefaultLogger(l *log.Logger) Logger

func LimitCodes

func LimitCodes(rs ResponseStatus, next Logger) Logger

func NopLogger

func NopLogger() Logger

type ResponseStatus

type ResponseStatus int
const (
	ResponseStatusSuccess     ResponseStatus = 1 << iota // 200-299
	ResponseStatusRedirect                               // 300-399
	ResponseStatusClientError                            // 400-499
	ResponseStatusServerError                            // 500-599

	ResponseStatusNone   ResponseStatus = 0
	ResponseStatusAll                   = ResponseStatusSuccess | ResponseStatusRedirect | ResponseStatusClientError | ResponseStatusServerError
	ResponseStatusErrors                = ResponseStatusClientError | ResponseStatusServerError
)

func (ResponseStatus) InRange

func (l ResponseStatus) InRange(statusCode int) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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