@@ -38,6 +38,63 @@ func TestLoggerContext(t *testing.T) {
3838 }
3939}
4040
41+ func TestSetLevel (t * testing.T ) {
42+ for _ , tc := range []struct {
43+ input string
44+ expected Level
45+ }{
46+ // Named levels
47+ {input : "trace" , expected : TraceLevel },
48+ {input : "debug" , expected : DebugLevel },
49+ {input : "info" , expected : InfoLevel },
50+ {input : "warn" , expected : WarnLevel },
51+ {input : "warning" , expected : WarnLevel },
52+ {input : "error" , expected : ErrorLevel },
53+ {input : "fatal" , expected : FatalLevel },
54+ {input : "panic" , expected : PanicLevel },
55+ {input : "INFO" , expected : InfoLevel },
56+ {input : "DEBUG" , expected : DebugLevel },
57+
58+ // Exact slog integer levels
59+ {input : "-8" , expected : TraceLevel },
60+ {input : "-4" , expected : DebugLevel },
61+ {input : "0" , expected : InfoLevel },
62+ {input : "4" , expected : WarnLevel },
63+ {input : "8" , expected : ErrorLevel },
64+ {input : "10" , expected : FatalLevel },
65+ {input : "12" , expected : PanicLevel },
66+
67+ // Nearest numeric levels (without going above)
68+ {input : "-10" , expected : TraceLevel },
69+ {input : "-6" , expected : DebugLevel },
70+ {input : "-5" , expected : DebugLevel },
71+ {input : "-2" , expected : InfoLevel },
72+ {input : "1" , expected : WarnLevel },
73+ {input : "2" , expected : WarnLevel },
74+ {input : "3" , expected : WarnLevel },
75+ {input : "6" , expected : ErrorLevel },
76+ {input : "7" , expected : ErrorLevel },
77+ {input : "9" , expected : FatalLevel },
78+ {input : "11" , expected : PanicLevel },
79+ {input : "13" , expected : PanicLevel },
80+ {input : "100" , expected : PanicLevel },
81+
82+ // Unparseable defaults to panic
83+ {input : "bogus" , expected : PanicLevel },
84+ {input : "" , expected : PanicLevel },
85+ } {
86+ t .Run (tc .input , func (t * testing.T ) {
87+ err := SetLevel (tc .input )
88+ if err != nil {
89+ t .Fatalf ("unexpected error: %v" , err )
90+ }
91+ if actual := GetLevel (); actual != tc .expected {
92+ t .Errorf ("expected level %v, got %v" , tc .expected , actual )
93+ }
94+ })
95+ }
96+ }
97+
4198func TestCompat (t * testing.T ) {
4299 expected := Fields {
43100 "hello1" : "world1" ,
0 commit comments