Documentation
¶
Overview ¶
Package slogscope is a custom slog Handler for Go, designed to allow fine-grained control over log levels on a per-package basis. This package provides an easy way to define different logging levels for individual packages, making it simpler to manage and debug large applications with varying levels of verbosity.
Please see https://github.com/apperia-de/slogscope for more details.
Index ¶
- Constants
- func NewNilHandler() slog.Handler
- type Config
- type Handler
- func (h *Handler) Enabled(_ context.Context, lvl slog.Level) bool
- func (h *Handler) GetConfig() Config
- func (h *Handler) GetLogLevel(level string) slog.Level
- func (h *Handler) Handle(ctx context.Context, rec slog.Record) error
- func (h *Handler) UseConfig(cfg Config)
- func (h *Handler) UseConfigFile(cfgFile ...string)
- func (h *Handler) UseConfigTemporarily(cfg Config, revert time.Duration)
- func (h *Handler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *Handler) WithGroup(name string) slog.Handler
- type HandlerOptions
- type Package
Constants ¶
const ( LogLevelDebug = "DEBUG" LogLevelInfo = "INFO" LogLevelWarn = "WARN" LogLevelError = "ERROR" )
Available log levels for the Config.
Variables ¶
This section is empty.
Functions ¶
func NewNilHandler ¶
NewNilHandler provides a nil slog.Handler for silencing slog.Log() calls.
Types ¶
type Handler ¶ added in v0.2.0
type Handler struct {
// contains filtered or unexported fields
}
func NewHandler ¶
func NewHandler(h slog.Handler, opts *HandlerOptions) *Handler
NewHandler creates a new slog.Handler
func (*Handler) GetConfig ¶ added in v0.2.0
GetConfig returns the current configuration, which may be adjusted and then used with UseConfig(cfg Config).
func (*Handler) GetLogLevel ¶ added in v1.0.0
GetLogLevel converts string log levels to slog.Level representation. Can be one of ["DEBUG", "INFO", "WARN" or "ERROR"]. Additionally, it accepts the aforementioned strings +/- an integer for representing additional log levels, not defined by the log/slog package. Example: DEBUG-2 or ERROR+4
func (*Handler) UseConfig ¶ added in v0.2.0
UseConfig takes a new Config and immediately applies it to the current configuration. It also disables any active file watcher.
func (*Handler) UseConfigFile ¶ added in v0.2.0
UseConfigFile takes a filename as an argument that will be used for watching a config file for changes. If no such filename is given, the Handler uses the already existing ConfigFile from the HandlerOptions or, if not present, falls back to the default config file (specified via defaultConfigFile).
func (*Handler) UseConfigTemporarily ¶ added in v0.2.0
UseConfigTemporarily takes a new Config and immediately applies it to the current configuration. In contrast to UseConfig(cfg Config), this function automatically reverts to the state before calling the method, after revert amount of time has elapsed.