(t *testing.T, format string, expect string)
| 45 | } |
| 46 | |
| 47 | func 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 | |
| 71 | func TestLogCallpath(t *testing.T) { |
| 72 | testCallpath(t, "%{callpath} %{message}", "TestLogCallpath.testCallpath.rec...rec.a.b.c") |
no test coverage detected