Documentation
¶
Index ¶
- Variables
- func New(level slog.Leveler, options ...Option) *slog.Logger
- func NewAsDefault(level, legacyLevel slog.Level, options ...Option) *slog.Logger
- func NewAsDefaultFromConfig(config Config, options ...Option) *slog.Logger
- func NewFromConfig(config Config, options ...Option) *slog.Logger
- func Wrap(inner slog.Handler, extractors []Extractor) slog.Handler
- type Config
- type Extractor
- type Option
Constants ¶
This section is empty.
Variables ¶
var Level slog.LevelVar
Level controls the level of the default logger. It exists to allow modifications to the level after the default logger is configured in NewAsDefault.
Functions ¶
func NewAsDefault ¶
NewAsDefault updates the global level with the given value and calls New with the new value.
The level used by the "log" package is set with the given legacy level. If the global log level is less than or equal to than the legacy level, the logs emitted by log.Println, etc. will be output. Otherwise they will be dropped.
func NewAsDefaultFromConfig ¶
NewAsDefaultFromConfig calls NewAsDefault with the given configuration.
func NewFromConfig ¶
NewFromConfig calls New with the given configuration.
Types ¶
type Config ¶
type Config struct { // Level sets the level for the logger. Level slog.Level `koanf:"level" default:"info"` // LegacyLevel sets the level for logs from the "log" package. This is only applied if using // NewAsDefaultFromConfig. LegacyLevel slog.Level `koanf:"level" default:"debug"` }
Config contains the configuration for the logger.
type Extractor ¶ added in v0.0.35
Extractor implementations are used to add attributes to a log record based on context metadata. One or more extractors can be added to the logger using the WithExtractors option.
type Option ¶ added in v0.0.35
type Option interface {
// contains filtered or unexported methods
}
Option implementations are used to apply optional configuration to a logger.
func WithExtractors ¶ added in v0.0.35
WithExtractors adds context extractors to the logger.
func WithSuppressSource ¶ added in v0.0.35
WithSuppressSource suppresses the source field of a log record. This is intended for testing where a deterministic log record is required.
func WithSuppressTime ¶ added in v0.0.35
WithSuppressTime suppresses the time field of a log record. This is intended for testing where a deterministic log record is required.
func WithWriter ¶ added in v0.0.35
WithWriter sets the output of a JSON logger. Defaults to os.Stdout.