Documentation
¶
Overview ¶
logging/logging.go
logging/recovermw.go
logging/requestmw.go
Index ¶
- Variables
- func BootstrapLogger() *zap.Logger
- func BuildLogger(level, env string) (*zap.Logger, error)
- func IsValidLogLevel(level string) bool
- func MustBuildLogger(level, env string) *zap.Logger
- func Recoverer(logger *zap.Logger) func(next http.Handler) http.Handler
- func RequestLogger(logger *zap.Logger) func(next http.Handler) http.Handler
Constants ¶
This section is empty.
Variables ¶
var ValidLogLevels = []string{"debug", "info", "warn", "error", "dpanic", "panic", "fatal"}
ValidLogLevels lists all valid zap log levels for validation.
Functions ¶
func BootstrapLogger ¶
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 ¶
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
IsValidLogLevel checks if the given level string is a valid zap log level. Comparison is case-insensitive.
func MustBuildLogger ¶
MustBuildLogger is a convenience for main() that wants to fatal on logger build failure.
func Recoverer ¶
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.
Types ¶
This section is empty.