This repository provides helper modules and packages for using log/slog effectively.
Package logger is a placeholder package for creating and using a project-specific slog.Logger across all modules in a program.
This package provides only two functions and will maintain this minimal API in the future:
- New() (*slog.Logger, error)
- NewName(name string) (*slog.Logger, error)
Note that New internally calls NewName, effectively providing a single core function.
NewName returns a slog.Logger created based on the value of an environment variable. However, this functionality is specific to this package and may not be suitable for all programs.
To customize the logger for your project:
- Create a new module with a custom
logger
package. - Implement your own
New
andNewName
functions that return a project-specific slog.Logger. - Replace the logger module in the package containing main:
go mod edit -replace github.com/goaux/slog/logger=<project-specific-logger>
This replacement ensures that all modules using the github.com/goaux/slog/logger package will use your project-specific logger instead of this placeholder package.
Package slogctx provides context-aware attribute management for the standard [log/slog] package.