-
Notifications
You must be signed in to change notification settings - Fork 1
/
log_test.go
44 lines (34 loc) · 830 Bytes
/
log_test.go
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cog
import (
"bytes"
"fmt"
"testing"
"github.com/kovetskiy/lorg"
"github.com/reconquest/karma-go"
"github.com/stretchr/testify/assert"
)
func TestFatal(t *testing.T) {
test := assert.New(t)
_ = test
outBuffer := bytes.NewBuffer(nil)
out := lorg.NewLog()
out.SetOutput(outBuffer)
out.SetFormat(lorg.NewFormat(`${level} %s`))
logger := NewLogger(out)
senderBuffer := bytes.NewBuffer(nil)
logger.SetExiter(func(code int) {
senderBuffer.WriteString(fmt.Sprintf("exit %d\n", code))
})
logger.SetSender(func(lvl lorg.Level, msg karma.Hierarchical) error {
senderBuffer.WriteString(lvl.String() + " " + msg.String() + "\n")
return nil
})
logger.Warning("warning")
logger.Fatal("fatal")
test.EqualValues(
"WARNING warning\n"+
"FATAL fatal\n"+
"exit 1\n",
senderBuffer.String(),
)
}