-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext_formatter_test.go
More file actions
68 lines (56 loc) · 1.56 KB
/
text_formatter_test.go
File metadata and controls
68 lines (56 loc) · 1.56 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package logrus_formatter
import (
"fmt"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/sirupsen/logrus"
"testing"
)
type LogOutput struct {
buffer string
}
func (o *LogOutput) Write(p []byte) (int, error) {
o.buffer += string(p[:])
return len(p), nil
}
func (o *LogOutput) GetValue() string {
return o.buffer
}
func TestLogrusFormatter(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "LogrusFormatter Suite")
}
var _ = Describe("Formatter", func() {
var formatter *TextFormatter
var log *logrus.Logger
var output *LogOutput
BeforeEach(func() {
output = new(LogOutput)
formatter = new(TextFormatter)
log = logrus.New()
log.Out = output
log.Formatter = formatter
log.Level = logrus.DebugLevel
})
Describe("logfmt output", func() {
It("should output simple message", func() {
formatter.SetFormat(TagBL, FieldKeyLevel, TagBR, FieldKeyMsg)
log.Debug("test")
Ω(output.GetValue()).Should(Equal("[DEBG] test\n"))
})
It("should output message with additional field", func() {
formatter.SetFormat(FieldKeyLevel, FieldKeyMsg)
log.WithFields(logrus.Fields{"animal": "walrus"}).Debug("test")
Ω(output.GetValue()).Should(Equal("DEBG test (animal=\"walrus\")\n"))
})
})
Describe("Formatted output", func() {
It("should output formatted message", func() {
formatter.SetFormat(TagBL, FieldKeyTime, TagBR, FieldKeyLevel, FieldKeyFile, TaGColon, FieldKeyFunc, TaGColon, FieldKeyLine, FieldKeyMsg)
log.Warnln("warnning test ")
fmt.Println(output.GetValue())
})
})
Describe("Theming support", func() {
})
})