zerochi

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2025 License: MIT Imports: 4 Imported by: 0

README

zerochi

zerochi provides a simple logging middleware for chi v5 using zerolog. It will also log and recover panics.

Usage

Grab the module:

go get -u github.com/Xiol/zerochi

Then set up the middleware:

import (
    "github.com/rs/zerolog/log"
    "github.com/Xiol/zerochi"
    "github.com/go-chi/chi/v5"
)

func main() {
    r := chi.NewRouter()
    r.Use(zerochi.Logger(&log.Logger))  // To use the default logger

    // ...
}

If you have paths that you don't want cluttering up your logs, you can use zerochi.SetSilentPaths() to avoid logging requests to those paths:

zerochi.SetSilentPaths("/ping", "/health")

The log message that accompanies each log line can also be changed:

zerochi.LogMessage = "api request"

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LogMessage = "handled request"

LogMessage is the log message associated with each log line.

Functions

func Logger

func Logger(log *zerolog.Logger) func(next http.Handler) http.Handler

func SetSilentPaths

func SetSilentPaths(paths ...string)

SetSilentPaths disables logging for the provided paths, e.g. "/health", "/metrics"

Types

This section is empty.

Jump to

Keyboard shortcuts

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