refactor(eventlog) extract entry
License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
Brian Tiger Chow committed
Nov 16, 2014 at 05:12 UTC
e906dcd862bd1cfb9b228ceda4fad746f34187cb
2 files changed
+39
-34
util/eventlog/entry.go
new
+39
@@ -0,0 +1,39 @@
1
+package eventlog
2
+
3
+import (
4
+ "time"
5
+
6
+ "github.com/jbenet/go-ipfs/util"
7
+ "github.com/maybebtc/logrus"
8
+)
9
+
10
+type entry struct {
11
+ loggables []Loggable
12
+ system string
13
+ event string
14
+}
15
+
16
+// Log logs the event unconditionally (regardless of log level)
17
+// TODO add support for leveled-logs once we decide which levels we want
18
+// for our structured logs
19
+func (e *entry) Log() {
20
+ e.log()
21
+}
22
+
23
+// log is a private method invoked by the public Log, Info, Error methods
24
+func (e *entry) log() {
25
+ // accumulate metadata
26
+ accum := Metadata{}
27
+ for _, loggable := range e.loggables {
28
+ accum = DeepMerge(accum, loggable.Loggable())
29
+ }
30
+
31
+ // apply final attributes to reserved keys
32
+ // TODO accum["level"] = level
33
+ accum["event"] = e.event
34
+ accum["system"] = e.system
35
+ accum["time"] = util.FormatRFC3339(time.Now())
36
+
37
+ // TODO roll our own event logger
38
+ logrus.WithFields(map[string]interface{}(accum)).Info(e.event)
39
+}
util/eventlog/log.go
-34
@@ -1,10 +1,7 @@
1
package eventlog
2
3
import (
4
- "time"
5
-
4
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
7
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/Sirupsen/logrus"
5
logging "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-logging"
6
"github.com/jbenet/go-ipfs/util"
7
)
@@ -91,34 +88,3 @@ func (el *eventLogger) Event(ctx context.Context, event string, metadata ...Logg
88
89
e.Log() // TODO replace this when leveled-logs have been implemented
90
}
94
-
95
-type entry struct {
96
- loggables []Loggable
97
- system string
98
- event string
99
-}
100
-
101
-// Log logs the event unconditionally (regardless of log level)
102
-// TODO add support for leveled-logs once we decide which levels we want
103
-// for our structured logs
104
-func (e *entry) Log() {
105
- e.log()
106
-}
107
-
108
-// log is a private method invoked by the public Log, Info, Error methods
109
-func (e *entry) log() {
110
- // accumulate metadata
111
- accum := Metadata{}
112
- for _, loggable := range e.loggables {
113
- accum = DeepMerge(accum, loggable.Loggable())
114
- }
115
-
116
- // apply final attributes to reserved keys
117
- // TODO accum["level"] = level
118
- accum["event"] = e.event
119
- accum["system"] = e.system
120
- accum["time"] = util.FormatRFC3339(time.Now())
121
-
122
- // TODO roll our own event logger
123
- logrus.WithFields(map[string]interface{}(accum)).Info(e.event)
124
-}