MCPcopy
hub / github.com/op/go-logging / testCallpath

Function testCallpath

log_test.go:47–69  ·  view source on GitHub ↗
(t *testing.T, format string, expect string)

Source from the content-addressed store, hash-verified

45}
46
47func testCallpath(t *testing.T, format string, expect string) {
48 buf := &bytes.Buffer{}
49 SetBackend(NewLogBackend(buf, "", log.Lshortfile))
50 SetFormatter(MustStringFormatter(format))
51
52 logger := MustGetLogger("test")
53 rec(logger, 6)
54
55 parts := strings.SplitN(buf.String(), " ", 3)
56
57 // Verify that the correct filename is registered by the stdlib logger
58 if !strings.HasPrefix(parts[0], "log_test.go:") {
59 t.Errorf("incorrect filename: %s", parts[0])
60 }
61 // Verify that the correct callpath is registered by go-logging
62 if !strings.HasPrefix(parts[1], expect) {
63 t.Errorf("incorrect callpath: %s", parts[1])
64 }
65 // Verify that the correct message is registered by go-logging
66 if !strings.HasPrefix(parts[2], "test callpath") {
67 t.Errorf("incorrect message: %s", parts[2])
68 }
69}
70
71func TestLogCallpath(t *testing.T) {
72 testCallpath(t, "%{callpath} %{message}", "TestLogCallpath.testCallpath.rec...rec.a.b.c")

Callers 1

TestLogCallpathFunction · 0.85

Calls 8

SetBackendFunction · 0.85
SetFormatterFunction · 0.85
MustStringFormatterFunction · 0.85
MustGetLoggerFunction · 0.85
recFunction · 0.85
StringMethod · 0.80
ErrorfMethod · 0.80
NewLogBackendFunction · 0.70

Tested by

no test coverage detected