MCPcopy
hub / github.com/rs/zerolog / TestPanicLevel

Function TestPanicLevel

log_test.go:963–994  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

961}
962
963func 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
996func TestFatalLevel(t *testing.T) {
997 lw := &levelWriter{

Callers

nothing calls this directly

Calls 7

SetGlobalLevelFunction · 0.85
NewFunction · 0.85
LevelMethod · 0.80
MsgMethod · 0.80
PanicMethod · 0.80
WithLevelMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected