refactor(eventlog) use polite formatter as a direct dependency
License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
Brian Tiger Chow committed
Nov 16, 2014 at 09:49 UTC
ddb0189b900f3c896cc5d64e7992de526351334e
2 files changed
+19
-1
util/eventlog/option.go
+1
-1
@@ -17,7 +17,7 @@ func Configure(options ...Option) {
17
18
// LdJSONFormatter formats the event log as line-delimited JSON
19
var LdJSONFormatter = func() {
20
- logrus.SetFormatter(&logrus.PoliteJSONFormatter{})
20
+ logrus.SetFormatter(&PoliteJSONFormatter{})
21
}
22
23
var TextFormatter = func() {
util/eventlog/polite_json_formatter.go
new
+18
@@ -0,0 +1,18 @@
1
+package eventlog
2
+
3
+import (
4
+ "encoding/json"
5
+ "fmt"
6
+
7
+ "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/maybebtc/logrus"
8
+)
9
+
10
+type PoliteJSONFormatter struct{}
11
+
12
+func (f *PoliteJSONFormatter) Format(entry *logrus.Entry) ([]byte, error) {
13
+ serialized, err := json.Marshal(entry.Data)
14
+ if err != nil {
15
+ return nil, fmt.Errorf("Failed to marshal fields to JSON, %v", err)
16
+ }
17
+ return append(serialized, '\n'), nil
18
+}