logging

package
v0.1.36 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

logging/logging.go

logging/recovermw.go

logging/requestmw.go

Index

Constants

This section is empty.

Variables

View Source
var ValidLogLevels = []string{"debug", "info", "warn", "error", "dpanic", "panic", "fatal"}

ValidLogLevels lists all valid zap log levels for validation.

Functions

func BootstrapLogger

func BootstrapLogger() *zap.Logger

BootstrapLogger returns a development-friendly logger for early startup. It's safe to use before config is loaded and should log to stderr.

func BuildLogger

func BuildLogger(level, env string) (*zap.Logger, error)

BuildLogger constructs the final logger based on log level and env. If env is "prod", it uses a JSON encoder; otherwise, it uses the development config.

Valid log levels are: debug, info, warn, error, dpanic, panic, fatal (case-insensitive). If an invalid level is provided, it defaults to "info" and logs a warning to stderr so the misconfiguration is visible.

func IsValidLogLevel added in v0.1.19

func IsValidLogLevel(level string) bool

IsValidLogLevel checks if the given level string is a valid zap log level. Comparison is case-insensitive.

func MustBuildLogger

func MustBuildLogger(level, env string) *zap.Logger

MustBuildLogger is a convenience for main() that wants to fatal on logger build failure.

func Recoverer

func Recoverer(logger *zap.Logger) func(next http.Handler) http.Handler

Recoverer returns a middleware that recovers from panics, logs them with a stack trace, and returns HTTP 500 if headers haven't been written yet.

If the panic occurs after response headers have already been sent, the middleware logs the panic but cannot change the response status code. In this case, it logs an additional warning indicating the response may be incomplete.

func RequestLogger

func RequestLogger(logger *zap.Logger) func(next http.Handler) http.Handler

RequestLogger returns a middleware that logs HTTP requests with method, path, status, bytes, latency, remote IP, user agent, referer, and request ID.

Types

This section is empty.

Jump to

Keyboard shortcuts

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