config

package
v3.0.0-...-53ae084 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Namespace string
	Pretty    bool
	Level     slog.Level
}

func FromOptions

func FromOptions(opts ...Option) *Config

FromOptions returns a populated config derived from the provided Options

type Option

type Option func(cfg *Config)
var FromEnv Option = func(cfg *Config) {
	humanLog, _ := strconv.ParseBool(os.Getenv("HUMAN_LOG"))
	cfg.Pretty = humanLog

	if s := os.Getenv("LOG_LEVEL"); s != "" {
		if l, err := levelFromString(s); err == nil {
			cfg.Level = l
		}
	}
}

FromEnv is a config option that processes environment variables and populates the config with the contents of those vars

var Pretty Option = func(cfg *Config) {
	cfg.Pretty = true
}

Pretty is an option that makes the output human-readable

func Level

func Level(l int) Option

Level returns a config option that populates a config with the log level of the logger

func Namespace

func Namespace(ns string) Option

Namespace returns a config option that populates a config with the namespace of the logger

Jump to

Keyboard shortcuts

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