From f6c22babbb6592088e2ad60410e034219036ca33 Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Fri, 9 Aug 2024 10:20:26 -0400 Subject: [PATCH] document the slag package (#22) Signed-off-by: Jason Hall --- slag/flag.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/slag/flag.go b/slag/flag.go index f918fde..790175b 100644 --- a/slag/flag.go +++ b/slag/flag.go @@ -1,3 +1,19 @@ +// 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. package slag import "log/slog"