...
Source file
src/log/slog/example_log_level_test.go
1
2
3
4
5 package slog_test
6
7 import (
8 "log"
9 "log/slog"
10 "log/slog/internal/slogtest"
11 "os"
12 )
13
14
15
16 func ExampleSetLogLoggerLevel_log() {
17 defer log.SetFlags(log.Flags())
18 log.SetFlags(0)
19 defer log.SetOutput(log.Writer())
20 log.SetOutput(os.Stdout)
21
22
23 log.Print("log debug")
24 slog.Debug("debug")
25 slog.Info("info")
26
27
28 currentLogLevel := slog.SetLogLoggerLevel(slog.LevelDebug)
29 defer slog.SetLogLoggerLevel(currentLogLevel)
30
31 log.Print("log debug")
32 slog.Debug("debug")
33 slog.Info("info")
34
35
36
37
38
39
40
41 }
42
43
44
45
46 func ExampleSetLogLoggerLevel_slog() {
47
48 currentLogLevel := slog.SetLogLoggerLevel(slog.LevelError)
49 defer slog.SetLogLoggerLevel(currentLogLevel)
50
51 defer slog.SetDefault(slog.Default())
52 slog.SetDefault(slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ReplaceAttr: slogtest.RemoveTime})))
53
54 log.Print("error")
55
56
57
58 }
59
View as plain text