flog

package
v0.0.0-...-570c91f Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package flog provides a set of fiber.Ctx helpers for zerolog.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccessHandler

func AccessHandler(f func(ctx *fiber.Ctx, duration time.Duration)) fiber.Handler

AccessHandler returns a handler that call f after each request.

func CtxWithID

func CtxWithID(ctx context.Context, id xid.ID) context.Context

CtxWithID adds the given xid.ID to the context

func CustomHeaderHandler

func CustomHeaderHandler(fieldKey, header string) func(ctx *fiber.Ctx) error

CustomHeaderHandler adds given header from request's header as a field to the context's logger using fieldKey as field key.

func DebugFrom

func DebugFrom(ctx *fiber.Ctx, name string) *zerolog.Event

func ErrorFrom

func ErrorFrom(ctx *fiber.Ctx, name string) *zerolog.Event

func FatalFrom

func FatalFrom(ctx *fiber.Ctx, name string) *zerolog.Event

func FromFiberCtx

func FromFiberCtx(r *fiber.Ctx) *zerolog.Logger

FromFiberCtx gets the logger in the request's context. This is a shortcut for log.Ctx(r.UserContext())

func IDFromCtx

func IDFromCtx(ctx context.Context) (id xid.ID, ok bool)

IDFromCtx returns the unique id associated to the context if any.

func IDFromFiberCtx

func IDFromFiberCtx(r *fiber.Ctx) (id xid.ID, ok bool)

IDFromFiberCtx returns the unique id associated to the *fiber.Ctx if any.

func InfoFrom

func InfoFrom(ctx *fiber.Ctx, name string) *zerolog.Event

func MethodHandler

func MethodHandler(fieldKey string) func(ctx *fiber.Ctx) error

MethodHandler adds the request method as a field to the context's logger using fieldKey as field key.

func NewHandlerMiddleware

func NewHandlerMiddleware(log zerolog.Logger) func(*fiber.Ctx) error

NewHandlerMiddleware injects log into requests context.

func PanicFrom

func PanicFrom(ctx *fiber.Ctx, name string) *zerolog.Event

func PenguinIDHandler

func PenguinIDHandler(fieldKey string) func(ctx *fiber.Ctx) error

PenguinIDHandler adds the request's penguin id as a field to the context's logger

func RefererHandler

func RefererHandler(fieldKey string) func(ctx *fiber.Ctx) error

RefererHandler adds the request's referer as a field to the context's logger using fieldKey as field key.

func RemoteAddrHandler

func RemoteAddrHandler(fieldKey string) func(ctx *fiber.Ctx) error

RemoteAddrHandler adds the request's remote address as a field to the context's logger using fieldKey as field key.

func RequestHandler

func RequestHandler(fieldKey string) func(ctx *fiber.Ctx) error

RequestHandler adds the request method and URL as a field to the context's logger using fieldKey as field key.

func RequestIDHandler

func RequestIDHandler(fieldKey, headerName string) fiber.Handler

RequestIDHandler returns a handler setting a unique id to the request which can be gathered using IDFromFiberCtx(req). This generated id is added as a field to the logger using the passed fieldKey as field name. The id is also added as a response header if the headerName is not empty.

The generated id is a URL safe base64 encoded mongo object-id-like unique id. Mongo unique id generation algorithm has been selected as a trade-off between size and ease of use: UUID is less space efficient and snowflake requires machine configuration.

func SetFiberCtxWithID

func SetFiberCtxWithID(ctx *fiber.Ctx, id xid.ID)

FiberCtxWithID adds the given xid.ID to the UserContext of *fiber.Ctx

func TraceFrom

func TraceFrom(ctx *fiber.Ctx, name string) *zerolog.Event

Logger Level Method Helpers

func URLHandler

func URLHandler(fieldKey string) func(ctx *fiber.Ctx) error

URLHandler adds the requested URL as a field to the context's logger using fieldKey as field key.

func UpdateContext

func UpdateContext(ctx *fiber.Ctx, f func(c zerolog.Context) zerolog.Context)

UpdateContext updates the context of the logger in the request's context.

func UserAgentHandler

func UserAgentHandler(fieldKey string) func(ctx *fiber.Ctx) error

UserAgentHandler adds the request's user-agent as a field to the context's logger using fieldKey as field key.

func WarnFrom

func WarnFrom(ctx *fiber.Ctx, name string) *zerolog.Event

Types

This section is empty.

Jump to

Keyboard shortcuts

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