| 961 | } |
| 962 | |
| 963 | func TestPanicLevel(t *testing.T) { |
| 964 | lw := &levelWriter{ |
| 965 | ops: []struct { |
| 966 | l Level |
| 967 | p string |
| 968 | }{}, |
| 969 | } |
| 970 | |
| 971 | // Allow extra-verbose logs. |
| 972 | SetGlobalLevel(TraceLevel - 1) |
| 973 | log := New(lw).Level(TraceLevel - 1) |
| 974 | |
| 975 | // Catch the panic from log.Panic().Msg("1") |
| 976 | defer func() { |
| 977 | if r := recover(); r == nil { |
| 978 | t.Error("expected panic from log.Panic()") |
| 979 | } |
| 980 | }() |
| 981 | log.Panic().Msg("1") |
| 982 | log.WithLevel(PanicLevel).Msg("2") |
| 983 | |
| 984 | want := []struct { |
| 985 | l Level |
| 986 | p string |
| 987 | }{ |
| 988 | {PanicLevel, `{"level":"panic","message":"1"}` + "\n"}, |
| 989 | {PanicLevel, `{"level":"panic","message":"2"}` + "\n"}, |
| 990 | } |
| 991 | if got := lw.ops; !reflect.DeepEqual(got, want) { |
| 992 | t.Errorf("invalid ops:\ngot:\n%v\nwant:\n%v", got, want) |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | func TestFatalLevel(t *testing.T) { |
| 997 | lw := &levelWriter{ |