File: text_test.go

package info (click to toggle)
golang-github-bep-logg 0.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 256 kB
  • sloc: makefile: 9
file content (25 lines) | stat: -rw-r--r-- 706 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package text_test

import (
	"bytes"
	"testing"

	qt "github.com/frankban/quicktest"

	"github.com/bep/logg"
	"github.com/bep/logg/handlers/text"
)

func TestTextHandler(t *testing.T) {
	var buf bytes.Buffer
	l := logg.New(logg.Options{Level: logg.LevelInfo, Handler: text.New(&buf, text.Options{Separator: "|"})})
	info := l.WithLevel(logg.LevelInfo)

	info.WithField("user", "tj").WithField("id", "123").Log(logg.String("hello"))
	info.WithField("user", "tj").Log(logg.String("world"))
	info.WithField("user", "tj").WithLevel(logg.LevelError).Log(logg.String("boom"))

	expected := "INFO|hello|user=tj|id=123\nINFO|world|user=tj\nERROR|boom|user=tj\n"

	qt.Assert(t, buf.String(), qt.Equals, expected)
}