Documentation
¶
Index ¶
- Variables
- func New(level slog.Leveler, options ...Option) (*slog.Logger, error)
- func NewAsDefault(level, legacyLevel slog.Level, options ...Option) (*slog.Logger, error)
- func NewAsDefaultFromConfig(config Config, options ...Option) (*slog.Logger, error)
- func NewFromConfig(config Config, options ...Option) (*slog.Logger, error)
- 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. Logs emitted below the configured level will be dropped.
Level slog.Level `koanf:"level" default:"info"`
// LegacyLevel sets the level for logs from the "log" package. This is only applied if using
// NewAsDefaultFromConfig.
//
// Unlike Level, this does not act as a filtering threshold. Instead, it creates the concept of
// a level in the "log" package and causes any logs output by uses of that package to use the
// configured level. These logs may subsequently be filtered out depending on the value of
// Level.
LegacyLevel slog.Level `koanf:"legacylevel" default:"debug"`
// Enable the JSON logging handler. This causes logs to be output to stdout under the assumption
// that they will be pulled from the Node the Pod is scheduled upon. At least one of
// EnableJSONHandler or EnableOtelHandler must be set to true.
EnableJSONHandler bool `koanf:"enablejsonhandler" default:"true"`
// Enable the OpenTelemetry logging handler. This causes logs to be periodically pushed to the
// configured endpoint. At least one of EnableJSONHandler or EnableOtelHandler must be set to
// true.
EnableOtelHandler bool `koanf:"enableotelhandler"`
}
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 EnableJSONHandler ¶ added in v0.4.58
EnableJSONHandler enables the output of JSON logs to the configured writer.
func EnableOtelHandler ¶ added in v0.4.58
EnableOtelHandler enables the OpenTelemetry log handler which exports logs to the configured endpoint.
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.