chizap

package
v0.0.0-...-91bc0ee Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package chizap implements the zap logging middleware for chi. it's heavily influenced by gin middleware: https://github.com/thinkgos/zap

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chizap

func Chizap(logger *zap.Logger, timeFormat string, utc bool) func(http.Handler) http.Handler

Chizap returns http middleware that logs requests using uber-go/zap.

It receives:

  1. A time package format string (e.g. time.RFC3339).
  2. A boolean stating whether to use UTC time zone or local.

func Logger

func Logger(logger *zap.Logger, opts ...Option) func(next http.Handler) http.Handler

Logger returns http middleware that logs requests using uber-go/zap.

Default option:

  1. A time package format string (e.g. time.RFC3339).(default time.RFC3339Nano)
  2. Use time zone.(e.g. utc time zone).(default local).
  3. Custom fields.(default nil)

func Recovery

func Recovery(logger *zap.Logger, stack bool, opts ...Option) func(next http.Handler) http.Handler

Recovery returns http middleware that recovers from any panics and logs requests using uber-go/zap. Errors are logged using zap.Error(). The stack parameter enables/disables output of the stack info. stack info can be very large.

func RecoveryWithZap

func RecoveryWithZap(logger *zap.Logger, stack bool) func(http.Handler) http.Handler

RecoveryWithZap returns http middleware that recovers from any panics and logs requests using uber-go/zap. Errors are logged using zap.Error(). The stack parameter enables/disables output of the stack info. stack info can be very large.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config is the configuration for logger/recover

type Option

type Option func(c *Config)

Option is a functional configuration option

func WithCustomFields

func WithCustomFields(fields ...func(c context.Context, r *http.Request) zap.Field) Option

WithCustomFields appends optional custom fields to be logged.

func WithTimeFormat

func WithTimeFormat(layout string) Option

WithTimeFormat allows optionally passing a time package format string (e.g. time.RFC3339). (default time.RFC3339Nano).

func WithUTC

func WithUTC(b bool) Option

WithUTC toggles between UTC or local time. (default local).

Jump to

Keyboard shortcuts

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