| 1 | package text_test |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "testing" |
| 6 | |
| 7 | qt "github.com/frankban/quicktest" |
| 8 | |
| 9 | "github.com/bep/logg" |
| 10 | "github.com/bep/logg/handlers/text" |
| 11 | ) |
| 12 | |
| 13 | func TestTextHandler(t *testing.T) { |
| 14 | var buf bytes.Buffer |
| 15 | l := logg.New(logg.Options{Level: logg.LevelInfo, Handler: text.New(&buf, text.Options{Separator: "|"})}) |
| 16 | info := l.WithLevel(logg.LevelInfo) |
| 17 | |
| 18 | info.WithField("user", "tj").WithField("id", "123").Log(logg.String("hello")) |
| 19 | info.WithField("user", "tj").Log(logg.String("world")) |
| 20 | info.WithField("user", "tj").WithLevel(logg.LevelError).Log(logg.String("boom")) |
| 21 | |
| 22 | expected := "INFO|hello|user=tj|id=123\nINFO|world|user=tj\nERROR|boom|user=tj\n" |
| 23 | |
| 24 | qt.Assert(t, buf.String(), qt.Equals, expected) |
| 25 | } |