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

Function TestLoggerAddCallerFunction

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

Source from the content-addressed store, hash-verified

657}
658
659func TestLoggerAddCallerFunction(t *testing.T) {
660 tests := []struct {
661 options []Option
662 loggerFunction string
663 sugaredFunction string
664 }{
665 {
666 options: opts(),
667 loggerFunction: "",
668 sugaredFunction: "",
669 },
670 {
671 options: opts(WithCaller(false)),
672 loggerFunction: "",
673 sugaredFunction: "",
674 },
675 {
676 options: opts(AddCaller()),
677 loggerFunction: "go.uber.org/zap.infoLog",
678 sugaredFunction: "go.uber.org/zap.infoLogSugared",
679 },
680 {
681 options: opts(AddCaller(), WithCaller(false)),
682 loggerFunction: "",
683 sugaredFunction: "",
684 },
685 {
686 options: opts(WithCaller(true)),
687 loggerFunction: "go.uber.org/zap.infoLog",
688 sugaredFunction: "go.uber.org/zap.infoLogSugared",
689 },
690 {
691 options: opts(WithCaller(true), WithCaller(false)),
692 loggerFunction: "",
693 sugaredFunction: "",
694 },
695 {
696 options: opts(AddCaller(), AddCallerSkip(1), AddCallerSkip(-1)),
697 loggerFunction: "go.uber.org/zap.infoLog",
698 sugaredFunction: "go.uber.org/zap.infoLogSugared",
699 },
700 {
701 options: opts(AddCaller(), AddCallerSkip(2)),
702 loggerFunction: "go.uber.org/zap.withLogger",
703 sugaredFunction: "go.uber.org/zap.withLogger",
704 },
705 {
706 options: opts(AddCaller(), AddCallerSkip(2), AddCallerSkip(3)),
707 loggerFunction: "runtime.goexit",
708 sugaredFunction: "runtime.goexit",
709 },
710 }
711 for _, tt := range tests {
712 withLogger(t, DebugLevel, tt.options, func(logger *Logger, logs *observer.ObservedLogs) {
713 // Make sure that sugaring and desugaring resets caller skip properly.
714 logger = logger.Sugar().Desugar()
715 infoLog(logger, "")
716 infoLogSugared(logger.Sugar(), "")

Callers

nothing calls this directly

Calls 10

optsFunction · 0.85
AddCallerFunction · 0.85
AddCallerSkipFunction · 0.85
infoLogFunction · 0.85
infoLogSugaredFunction · 0.85
DesugarMethod · 0.80
SugarMethod · 0.80
AllUntimedMethod · 0.80
WithCallerFunction · 0.70
withLoggerFunction · 0.70

Tested by

no test coverage detected