@cryptotaxi247 / kubo / commits / 210b5df78

use my go-logging fork

until https://github.com/op/go-logging/pull/30 is merged

Juan Batiz-Benet committed Oct 25, 2014 at 02:50 UTC 210b5df78c4c8003bab3dca6995aa88fe6b7287f
23 files changed +91 -21
Godeps/Godeps.json
+4 -4
@@ -87,6 +87,10 @@
87 "ImportPath": "github.com/jbenet/go-is-domain",
88 "Rev": "93b717f2ae17838a265e30277275ee99ee7198d6"
89 },
90 + {
91 + "ImportPath": "github.com/jbenet/go-logging",
92 + "Rev": "74bec4b83f6d45d1402c1e9d94c0c29e39f6e0ea"
93 + },
94 {
95 "ImportPath": "github.com/jbenet/go-msgio",
96 "Rev": "c9069ab79c95aa0686347b516972c7329c4391f2"
@@ -109,10 +113,6 @@
113 "ImportPath": "github.com/mitchellh/go-homedir",
114 "Rev": "7d2d8c8a4e078ce3c58736ab521a40b37a504c52"
115 },
112 - {
113 - "ImportPath": "github.com/op/go-logging",
114 - "Rev": "3df864a88c7f005e676db4f026a4fe2f14929be3"
115 - },
116 {
117 "ImportPath": "github.com/syndtr/goleveldb/leveldb",
118 "Rev": "99056d50e56252fbe0021d5c893defca5a76baf8"
Godeps/_workspace/src/github.com/jbenet/go-logging/.travis.yml renamed
Godeps/_workspace/src/github.com/jbenet/go-logging/CONTRIBUTORS renamed
Godeps/_workspace/src/github.com/jbenet/go-logging/LICENSE renamed
Godeps/_workspace/src/github.com/jbenet/go-logging/README.md renamed
-1
@@ -80,4 +80,3 @@ You can use `go get -u` to update the package.
80 For docs, see http://godoc.org/github.com/op/go-logging or run:
81
82 $ godoc github.com/op/go-logging
83 -
Godeps/_workspace/src/github.com/jbenet/go-logging/backend.go renamed
Godeps/_workspace/src/github.com/jbenet/go-logging/examples/example.go renamed
+1 -1
@@ -3,7 +3,7 @@ package main
3 import (
4 "os"
5
6 - "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/op/go-logging"
6 + "github.com/op/go-logging"
7 )
8
9 var log = logging.MustGetLogger("example")
Godeps/_workspace/src/github.com/jbenet/go-logging/examples/example.png renamed
Godeps/_workspace/src/github.com/jbenet/go-logging/format.go renamed
Godeps/_workspace/src/github.com/jbenet/go-logging/format_test.go renamed
Godeps/_workspace/src/github.com/jbenet/go-logging/level.go renamed
Godeps/_workspace/src/github.com/jbenet/go-logging/level_test.go renamed
Godeps/_workspace/src/github.com/jbenet/go-logging/log.go renamed
Godeps/_workspace/src/github.com/jbenet/go-logging/log_test.go renamed
Godeps/_workspace/src/github.com/jbenet/go-logging/logger.go renamed
+64 -10
@@ -55,6 +55,7 @@ type Record struct {
55 formatted string
56 }
57
58 +// Formatted returns the string-formatted version of a record.
59 func (r *Record) Formatted(calldepth int) string {
60 if r.formatted == "" {
61 var buf bytes.Buffer
@@ -64,6 +65,8 @@ func (r *Record) Formatted(calldepth int) string {
65 return r.formatted
66 }
67
68 +// Message returns a string message for outputting. Redacts any record args
69 +// that implement the Redactor interface
70 func (r *Record) Message() string {
71 if r.message == nil {
72 // Redact the arguments that implements the Redactor interface
@@ -78,12 +81,22 @@ func (r *Record) Message() string {
81 return *r.message
82 }
83
84 +// Logger is a logging unit. It controls the flow of messages to a given
85 +// (swappable) backend.
86 type Logger struct {
82 - Module string
87 + Module string
88 + backend LeveledBackend
89 + haveBackend bool
90 +}
91 +
92 +// SetBackend changes the backend of the logger.
93 +func (l *Logger) SetBackend(backend LeveledBackend) {
94 + l.backend = backend
95 + l.haveBackend = true
96 }
97
85 -// TODO call NewLogger and remove MustGetLogger?
98 // GetLogger creates and returns a Logger object based on the module name.
99 +// TODO call NewLogger and remove MustGetLogger?
100 func GetLogger(module string) (*Logger, error) {
101 return &Logger{Module: module}, nil
102 }
@@ -148,6 +161,11 @@ func (l *Logger) log(lvl Level, format string, args ...interface{}) {
161
162 // calldepth=2 brings the stack up to the caller of the level
163 // methods, Info(), Fatal(), etc.
164 + if l.haveBackend {
165 + l.backend.Log(lvl, 2, record)
166 + return
167 + }
168 +
169 defaultBackend.Log(lvl, 2, record)
170 }
171
@@ -178,33 +196,69 @@ func (l *Logger) Panicf(format string, args ...interface{}) {
196 panic(s)
197 }
198
181 -// Critical logs a message using CRITICAL as log level.
182 -func (l *Logger) Critical(format string, args ...interface{}) {
199 +// Critical logs a message using CRITICAL as log level. (fmt.Sprint())
200 +func (l *Logger) Critical(args ...interface{}) {
201 + s := fmt.Sprint(args...)
202 + l.log(CRITICAL, "%s", s)
203 +}
204 +
205 +// Criticalf logs a message using CRITICAL as log level.
206 +func (l *Logger) Criticalf(format string, args ...interface{}) {
207 l.log(CRITICAL, format, args...)
208 }
209
186 -// Error logs a message using ERROR as log level.
187 -func (l *Logger) Error(format string, args ...interface{}) {
210 +// Error logs a message using ERROR as log level. (fmt.Sprint())
211 +func (l *Logger) Error(args ...interface{}) {
212 + s := fmt.Sprint(args...)
213 + l.log(ERROR, "%s", s)
214 +}
215 +
216 +// Errorf logs a message using ERROR as log level.
217 +func (l *Logger) Errorf(format string, args ...interface{}) {
218 l.log(ERROR, format, args...)
219 }
220
221 // Warning logs a message using WARNING as log level.
192 -func (l *Logger) Warning(format string, args ...interface{}) {
222 +func (l *Logger) Warning(args ...interface{}) {
223 + s := fmt.Sprint(args...)
224 + l.log(WARNING, "%s", s)
225 +}
226 +
227 +// Warningf logs a message using WARNING as log level.
228 +func (l *Logger) Warningf(format string, args ...interface{}) {
229 l.log(WARNING, format, args...)
230 }
231
232 // Notice logs a message using NOTICE as log level.
197 -func (l *Logger) Notice(format string, args ...interface{}) {
233 +func (l *Logger) Notice(args ...interface{}) {
234 + s := fmt.Sprint(args...)
235 + l.log(NOTICE, "%s", s)
236 +}
237 +
238 +// Noticef logs a message using NOTICE as log level.
239 +func (l *Logger) Noticef(format string, args ...interface{}) {
240 l.log(NOTICE, format, args...)
241 }
242
243 // Info logs a message using INFO as log level.
202 -func (l *Logger) Info(format string, args ...interface{}) {
244 +func (l *Logger) Info(args ...interface{}) {
245 + s := fmt.Sprint(args...)
246 + l.log(INFO, "%s", s)
247 +}
248 +
249 +// Infof logs a message using INFO as log level.
250 +func (l *Logger) Infof(format string, args ...interface{}) {
251 l.log(INFO, format, args...)
252 }
253
254 // Debug logs a message using DEBUG as log level.
207 -func (l *Logger) Debug(format string, args ...interface{}) {
255 +func (l *Logger) Debug(args ...interface{}) {
256 + s := fmt.Sprint(args...)
257 + l.log(DEBUG, "%s", s)
258 +}
259 +
260 +// Debugf logs a message using DEBUG as log level.
261 +func (l *Logger) Debugf(format string, args ...interface{}) {
262 l.log(DEBUG, format, args...)
263 }
264
Godeps/_workspace/src/github.com/jbenet/go-logging/logger_test.go renamed
+18 -1
@@ -29,8 +29,25 @@ func TestRedact(t *testing.T) {
29 backend := InitForTesting(DEBUG)
30 password := Password("123456")
31 log := MustGetLogger("test")
32 - log.Debug("foo %s", password)
32 + log.Debugf("foo %s", password)
33 if "foo ******" != MemoryRecordN(backend, 0).Formatted(0) {
34 t.Errorf("redacted line: %v", MemoryRecordN(backend, 0))
35 }
36 }
37 +
38 +func TestPrivateBackend(t *testing.T) {
39 + stdBackend := InitForTesting(DEBUG)
40 + log := MustGetLogger("test")
41 + privateBackend := NewMemoryBackend(10240)
42 + lvlBackend := AddModuleLevel(privateBackend)
43 + lvlBackend.SetLevel(DEBUG, "")
44 + log.SetBackend(lvlBackend)
45 + log.Debug("to private backend")
46 + if stdBackend.size > 0 {
47 + t.Errorf("something in stdBackend, size of backend: %d", stdBackend.size)
48 + }
49 + if "to private baсkend" == MemoryRecordN(privateBackend, 0).Formatted(0) {
50 + t.Errorf("logged to defaultBackend: %s", MemoryRecordN(privateBackend, 0))
51 + }
52 +
53 +}
Godeps/_workspace/src/github.com/jbenet/go-logging/memory.go renamed
Godeps/_workspace/src/github.com/jbenet/go-logging/memory_test.go renamed
+2 -2
@@ -51,7 +51,7 @@ func TestMemoryBackend(t *testing.T) {
51
52 // Run 13 times, the resulting vector should be [5..12]
53 for i := 0; i < 13; i++ {
54 - log.Info("%d", i)
54 + log.Infof("%d", i)
55 }
56
57 if 8 != backend.size {
@@ -89,7 +89,7 @@ func TestChannelMemoryBackend(t *testing.T) {
89
90 // Run 13 times, the resulting vector should be [5..12]
91 for i := 0; i < 13; i++ {
92 - log.Info("%d", i)
92 + log.Infof("%d", i)
93 }
94 backend.Flush()
95
Godeps/_workspace/src/github.com/jbenet/go-logging/multi.go renamed
Godeps/_workspace/src/github.com/jbenet/go-logging/multi_test.go renamed
Godeps/_workspace/src/github.com/jbenet/go-logging/syslog.go renamed
unixfs/io/dagmodifier_test.go
+1 -1
@@ -6,7 +6,6 @@ import (
6 "io/ioutil"
7 "testing"
8
9 - "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/op/go-logging"
9 bs "github.com/jbenet/go-ipfs/blockservice"
10 "github.com/jbenet/go-ipfs/importer/chunk"
11 mdag "github.com/jbenet/go-ipfs/merkledag"
@@ -14,6 +13,7 @@ import (
13 u "github.com/jbenet/go-ipfs/util"
14
15 ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
16 + logging "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-logging"
17 )
18
19 func getMockDagServ(t *testing.T) *mdag.DAGService {
util/log.go
+1 -1
@@ -4,7 +4,7 @@ import (
4 "fmt"
5 "os"
6
7 - logging "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/op/go-logging"
7 + logging "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-logging"
8 )
9
10 func init() {