logger

package
v0.102.3 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package logger logs http responses See: https://github.com/elithrar/admission-control/blob/v0.6.7/request_logger.go#L40

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromContext

func FromContext(ctx context.Context) *slog.Logger

FromContext returns the *slog.Logger previously stored in ctx by NewContext. slog.Default() is returned otherwise.

func GetClientIP

func GetClientIP(r *http.Request) string

GetClientIP returns the client address from the x-forwarded-for header or the http.Request RemoteAddr field.

func LoggingMiddleware

func LoggingMiddleware(log *slog.Logger) func(h http.Handler) http.Handler

LoggingMiddleware returns a handler that adds a *slog.Logger to the request context.Context retrievable by FromContext. The returned handler is useful as the outer client facing edge of a middleware chain and includes attributes on the log messages.

func NewContext

func NewContext(ctx context.Context, log *slog.Logger) context.Context

func ResponseLogger

func ResponseLogger(next http.Handler) http.Handler

ResponseLogger logs responses at info level. Intended for a live production site to collect essential usage metrics.

Types

This section is empty.

Jump to

Keyboard shortcuts

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