slag

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: Apache-2.0 Imports: 1 Imported by: 9 modules, 4 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package slag provides a method for setting the log level from the command line.

func main() {
	var level slag.Level
	flag.Var(&level, "log-level", "log level")
	flag.Parse()
	slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: &level})))
}

See [./examples/logger](./examples/logger) for a full example.

This allows the log level to be set from the command line:

$ ./myprogram -log-level=debug

The slag.Level type is a wrapper around slog.Level that implements the flag.Value interface, as well as Cobra's pflag.Value interface.

func main() {
	var level slag.Level
	cmd := &cobra.Command{
		Use: "myprogram",
		...
	}
	cmd.PersistentFlags().Var(&level, "log-level", "log level")
	cmd.Execute()
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Level

type Level slog.Level

func (*Level) Level

func (l *Level) Level() slog.Level

func (*Level) Set

func (l *Level) Set(s string) error

func (*Level) String

func (l *Level) String() string

func (*Level) Type added in v1.5.1

func (l *Level) Type() string

Implements https://pkg.go.dev/github.com/spf13/pflag#Value

Jump to

Keyboard shortcuts

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