added loggables pkg
Juan Batiz-Benet committed
Dec 15, 2014 at 13:48 UTC
b9525f152469259a6dbe7e739a253b580a0a9c22
1 file changed
+28
util/eventlog/loggables/loggables.go
new
+28
@@ -0,0 +1,28 @@
1
+// Package loggables includes a bunch of transaltor functions for commonplace/stdlib
2
+// objects. This is boilerplate code that shouldn't change much, and not sprinkled
3
+// all over the place (i.e. gather it here).
4
+//
5
+// Note: it may make sense to put all stdlib Loggable functions in the eventlog
6
+// package. Putting it here for now in case we don't want to polute it.
7
+package loggables
8
+
9
+import (
10
+ "net"
11
+
12
+ log "github.com/jbenet/go-ipfs/util/eventlog"
13
+)
14
+
15
+// NetConn returns an eventlog.Metadata with the conn addresses
16
+func NetConn(c net.Conn) log.Loggable {
17
+ return log.Metadata{
18
+ "localAddr": c.LocalAddr(),
19
+ "remoteAddr": c.RemoteAddr(),
20
+ }
21
+}
22
+
23
+// Error returns an eventlog.Metadata with an error
24
+func Error(e error) log.Loggable {
25
+ return log.Metadata{
26
+ "error": e.Error(),
27
+ }
28
+}