-
Notifications
You must be signed in to change notification settings - Fork 4
/
gelf_test.go
39 lines (34 loc) · 919 Bytes
/
gelf_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
package formatters
import (
"bytes"
"encoding/json"
"log/syslog"
"testing"
"github.com/sirupsen/logrus"
)
func TestGelfFormatter_Format(t *testing.T) {
log := logrus.New()
log.Formatter = NewGelf("testhost")
buffer := new(bytes.Buffer)
log.Out = buffer
log.WithField("foo", "bar").Info("great test message")
var message map[string]interface{}
err := json.Unmarshal(buffer.Bytes(), &message)
if err != nil {
t.Error(err)
}
expectations := map[string]interface{}{
"host": "testhost",
"level": float64(syslog.LOG_INFO),
"short_message": "great test message",
"version": GelfVersion,
"_level_name": "INFORMATIONAL",
"_foo": "bar",
"_line": 17.,
}
for key, expected := range expectations {
if message[key] != expected {
t.Errorf("invalid log object: expected value for key '%s' was '%s', found '%s'", key, expected, message[key])
}
}
}