weblog

package
v0.0.0-...-514cf28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2024 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Overview

Package weblog provides a configurable logging system based on slog by providing convenient configuration and initialization options.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLogType  = errors.New("invalid log type")
	ErrInvalidLogLevel = errors.New("invalid log level")
	ErrOpenLogFile     = errors.New("failed to open log file")
)

Functions

func Init

func Init(config Config) error

Init validates config and initializes the default slog logger.

func Levels

func Levels() []string

Levels generates a sorted list of valid log levels from the logLevelMap.

func ParseLogLevel

func ParseLogLevel(level string) (slog.Level, error)

ParseLogLevel converts a log level string to its corresponding slog.Level. An empty string returns the default value of slog.Level with no error. If the level string is invalid, it returns an error.

Types

type Config

type Config struct {
	Filename  string // Path to the log file. Uses stderr if empty.
	Type      string // Log format: 'json' or 'text'.
	Level     string // Log level as a string.
	AddSource bool   // If true, includes source code position in logs.
}

Config defines the configuration options for logging.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL