Documentation
¶
Overview ¶
Package flog provides a set of fiber.Ctx helpers for zerolog.
Index ¶
- func AccessHandler(f func(ctx *fiber.Ctx, duration time.Duration)) fiber.Handler
- func CtxWithID(ctx context.Context, id xid.ID) context.Context
- func CustomHeaderHandler(fieldKey, header string) func(ctx *fiber.Ctx) error
- func DebugFrom(ctx *fiber.Ctx, name string) *zerolog.Event
- func ErrorFrom(ctx *fiber.Ctx, name string) *zerolog.Event
- func FatalFrom(ctx *fiber.Ctx, name string) *zerolog.Event
- func FromFiberCtx(r *fiber.Ctx) *zerolog.Logger
- func IDFromCtx(ctx context.Context) (id xid.ID, ok bool)
- func IDFromFiberCtx(r *fiber.Ctx) (id xid.ID, ok bool)
- func InfoFrom(ctx *fiber.Ctx, name string) *zerolog.Event
- func MethodHandler(fieldKey string) func(ctx *fiber.Ctx) error
- func NewHandlerMiddleware(log zerolog.Logger) func(*fiber.Ctx) error
- func PanicFrom(ctx *fiber.Ctx, name string) *zerolog.Event
- func PenguinIDHandler(fieldKey string) func(ctx *fiber.Ctx) error
- func RefererHandler(fieldKey string) func(ctx *fiber.Ctx) error
- func RemoteAddrHandler(fieldKey string) func(ctx *fiber.Ctx) error
- func RequestHandler(fieldKey string) func(ctx *fiber.Ctx) error
- func RequestIDHandler(fieldKey, headerName string) fiber.Handler
- func SetFiberCtxWithID(ctx *fiber.Ctx, id xid.ID)
- func TraceFrom(ctx *fiber.Ctx, name string) *zerolog.Event
- func URLHandler(fieldKey string) func(ctx *fiber.Ctx) error
- func UpdateContext(ctx *fiber.Ctx, f func(c zerolog.Context) zerolog.Context)
- func UserAgentHandler(fieldKey string) func(ctx *fiber.Ctx) error
- func WarnFrom(ctx *fiber.Ctx, name string) *zerolog.Event
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AccessHandler ¶
AccessHandler returns a handler that call f after each request.
func CustomHeaderHandler ¶
CustomHeaderHandler adds given header from request's header as a field to the context's logger using fieldKey as field key.
func FromFiberCtx ¶
FromFiberCtx gets the logger in the request's context. This is a shortcut for log.Ctx(r.UserContext())
func IDFromFiberCtx ¶
IDFromFiberCtx returns the unique id associated to the *fiber.Ctx if any.
func MethodHandler ¶
MethodHandler adds the request method as a field to the context's logger using fieldKey as field key.
func NewHandlerMiddleware ¶
NewHandlerMiddleware injects log into requests context.
func PenguinIDHandler ¶
PenguinIDHandler adds the request's penguin id as a field to the context's logger
func RefererHandler ¶
RefererHandler adds the request's referer as a field to the context's logger using fieldKey as field key.
func RemoteAddrHandler ¶
RemoteAddrHandler adds the request's remote address as a field to the context's logger using fieldKey as field key.
func RequestHandler ¶
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 ¶
FiberCtxWithID adds the given xid.ID to the UserContext of *fiber.Ctx
func URLHandler ¶
URLHandler adds the requested URL as a field to the context's logger using fieldKey as field key.
func UpdateContext ¶
UpdateContext updates the context of the logger in the request's context.
func UserAgentHandler ¶
UserAgentHandler adds the request's user-agent as a field to the context's logger using fieldKey as field key.
Types ¶
This section is empty.