MCPcopy
hub / github.com/uber-go/zap / TestLoggerCustomOnPanic

Function TestLoggerCustomOnPanic

logger_test.go:839–961  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

837}
838
839func TestLoggerCustomOnPanic(t *testing.T) {
840 tests := []struct {
841 msg string
842 level zapcore.Level
843 opts []Option
844 finished bool
845 want []observer.LoggedEntry
846 recoverValue any
847 }{
848 {
849 msg: "panic with nil hook",
850 level: PanicLevel,
851 opts: opts(WithPanicHook(nil)),
852 finished: false,
853 want: []observer.LoggedEntry{
854 {
855 Entry: zapcore.Entry{Level: PanicLevel, Message: "foobar"},
856 Context: []Field{},
857 },
858 },
859 recoverValue: "foobar",
860 },
861 {
862 msg: "panic with noop hook",
863 level: PanicLevel,
864 opts: opts(WithPanicHook(zapcore.WriteThenNoop)),
865 finished: false,
866 want: []observer.LoggedEntry{
867 {
868 Entry: zapcore.Entry{Level: PanicLevel, Message: "foobar"},
869 Context: []Field{},
870 },
871 },
872 recoverValue: "foobar",
873 },
874 {
875 msg: "no panic with goexit hook",
876 level: PanicLevel,
877 opts: opts(WithPanicHook(zapcore.WriteThenGoexit)),
878 finished: false,
879 want: []observer.LoggedEntry{
880 {
881 Entry: zapcore.Entry{Level: PanicLevel, Message: "foobar"},
882 Context: []Field{},
883 },
884 },
885 recoverValue: nil,
886 },
887 {
888 msg: "dpanic no panic in development mode with goexit hook",
889 level: DPanicLevel,
890 opts: opts(WithPanicHook(zapcore.WriteThenGoexit), Development()),
891 finished: false,
892 want: []observer.LoggedEntry{
893 {
894 Entry: zapcore.Entry{Level: DPanicLevel, Message: "foobar"},
895 Context: []Field{},
896 },

Callers

nothing calls this directly

Calls 6

optsFunction · 0.85
WithPanicHookFunction · 0.85
DevelopmentFunction · 0.85
AllUntimedMethod · 0.80
withLoggerFunction · 0.70
LogMethod · 0.45

Tested by

no test coverage detected