diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index e8c83f96bce0c8862719851a0916ed371ab4802f..3bbcd876e99889ed5d42d47fc2ff2cb3a545ae4a 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -87,6 +87,10 @@ "ImportPath": "github.com/jbenet/go-is-domain", "Rev": "93b717f2ae17838a265e30277275ee99ee7198d6" }, + { + "ImportPath": "github.com/jbenet/go-logging", + "Rev": "74bec4b83f6d45d1402c1e9d94c0c29e39f6e0ea" + }, { "ImportPath": "github.com/jbenet/go-msgio", "Rev": "c9069ab79c95aa0686347b516972c7329c4391f2" @@ -109,10 +113,6 @@ "ImportPath": "github.com/mitchellh/go-homedir", "Rev": "7d2d8c8a4e078ce3c58736ab521a40b37a504c52" }, - { - "ImportPath": "github.com/op/go-logging", - "Rev": "3df864a88c7f005e676db4f026a4fe2f14929be3" - }, { "ImportPath": "github.com/syndtr/goleveldb/leveldb", "Rev": "99056d50e56252fbe0021d5c893defca5a76baf8" diff --git a/Godeps/_workspace/src/github.com/op/go-logging/.travis.yml b/Godeps/_workspace/src/github.com/jbenet/go-logging/.travis.yml similarity index 100% rename from Godeps/_workspace/src/github.com/op/go-logging/.travis.yml rename to Godeps/_workspace/src/github.com/jbenet/go-logging/.travis.yml diff --git a/Godeps/_workspace/src/github.com/op/go-logging/CONTRIBUTORS b/Godeps/_workspace/src/github.com/jbenet/go-logging/CONTRIBUTORS similarity index 100% rename from Godeps/_workspace/src/github.com/op/go-logging/CONTRIBUTORS rename to Godeps/_workspace/src/github.com/jbenet/go-logging/CONTRIBUTORS diff --git a/Godeps/_workspace/src/github.com/op/go-logging/LICENSE b/Godeps/_workspace/src/github.com/jbenet/go-logging/LICENSE similarity index 100% rename from Godeps/_workspace/src/github.com/op/go-logging/LICENSE rename to Godeps/_workspace/src/github.com/jbenet/go-logging/LICENSE diff --git a/Godeps/_workspace/src/github.com/op/go-logging/README.md b/Godeps/_workspace/src/github.com/jbenet/go-logging/README.md similarity index 99% rename from Godeps/_workspace/src/github.com/op/go-logging/README.md rename to Godeps/_workspace/src/github.com/jbenet/go-logging/README.md index 81d1705fca0406870b6f3f6a055ca5547ba865f6..ec5cf240544e04b0946a70072751d552e4d7802e 100644 --- a/Godeps/_workspace/src/github.com/op/go-logging/README.md +++ b/Godeps/_workspace/src/github.com/jbenet/go-logging/README.md @@ -80,4 +80,3 @@ You can use `go get -u` to update the package. For docs, see http://godoc.org/github.com/op/go-logging or run: $ godoc github.com/op/go-logging - diff --git a/Godeps/_workspace/src/github.com/op/go-logging/backend.go b/Godeps/_workspace/src/github.com/jbenet/go-logging/backend.go similarity index 100% rename from Godeps/_workspace/src/github.com/op/go-logging/backend.go rename to Godeps/_workspace/src/github.com/jbenet/go-logging/backend.go diff --git a/Godeps/_workspace/src/github.com/op/go-logging/examples/example.go b/Godeps/_workspace/src/github.com/jbenet/go-logging/examples/example.go similarity index 94% rename from Godeps/_workspace/src/github.com/op/go-logging/examples/example.go rename to Godeps/_workspace/src/github.com/jbenet/go-logging/examples/example.go index 58287ad0adaeb1e1aed44772b935f4222d8fd33f..28168d00e22b8dca36f682da63e4cd8742748184 100644 --- a/Godeps/_workspace/src/github.com/op/go-logging/examples/example.go +++ b/Godeps/_workspace/src/github.com/jbenet/go-logging/examples/example.go @@ -3,7 +3,7 @@ package main import ( "os" - "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/op/go-logging" + "github.com/op/go-logging" ) var log = logging.MustGetLogger("example") diff --git a/Godeps/_workspace/src/github.com/op/go-logging/examples/example.png b/Godeps/_workspace/src/github.com/jbenet/go-logging/examples/example.png similarity index 100% rename from Godeps/_workspace/src/github.com/op/go-logging/examples/example.png rename to Godeps/_workspace/src/github.com/jbenet/go-logging/examples/example.png diff --git a/Godeps/_workspace/src/github.com/op/go-logging/format.go b/Godeps/_workspace/src/github.com/jbenet/go-logging/format.go similarity index 100% rename from Godeps/_workspace/src/github.com/op/go-logging/format.go rename to Godeps/_workspace/src/github.com/jbenet/go-logging/format.go diff --git a/Godeps/_workspace/src/github.com/op/go-logging/format_test.go b/Godeps/_workspace/src/github.com/jbenet/go-logging/format_test.go similarity index 100% rename from Godeps/_workspace/src/github.com/op/go-logging/format_test.go rename to Godeps/_workspace/src/github.com/jbenet/go-logging/format_test.go diff --git a/Godeps/_workspace/src/github.com/op/go-logging/level.go b/Godeps/_workspace/src/github.com/jbenet/go-logging/level.go similarity index 100% rename from Godeps/_workspace/src/github.com/op/go-logging/level.go rename to Godeps/_workspace/src/github.com/jbenet/go-logging/level.go diff --git a/Godeps/_workspace/src/github.com/op/go-logging/level_test.go b/Godeps/_workspace/src/github.com/jbenet/go-logging/level_test.go similarity index 100% rename from Godeps/_workspace/src/github.com/op/go-logging/level_test.go rename to Godeps/_workspace/src/github.com/jbenet/go-logging/level_test.go diff --git a/Godeps/_workspace/src/github.com/op/go-logging/log.go b/Godeps/_workspace/src/github.com/jbenet/go-logging/log.go similarity index 100% rename from Godeps/_workspace/src/github.com/op/go-logging/log.go rename to Godeps/_workspace/src/github.com/jbenet/go-logging/log.go diff --git a/Godeps/_workspace/src/github.com/op/go-logging/log_test.go b/Godeps/_workspace/src/github.com/jbenet/go-logging/log_test.go similarity index 100% rename from Godeps/_workspace/src/github.com/op/go-logging/log_test.go rename to Godeps/_workspace/src/github.com/jbenet/go-logging/log_test.go diff --git a/Godeps/_workspace/src/github.com/op/go-logging/logger.go b/Godeps/_workspace/src/github.com/jbenet/go-logging/logger.go similarity index 73% rename from Godeps/_workspace/src/github.com/op/go-logging/logger.go rename to Godeps/_workspace/src/github.com/jbenet/go-logging/logger.go index 47bbd444b63cd6c73d4e425babbb3afd1768d54e..867916dbf65a7b9d4502c52d2f220729b8def3fa 100644 --- a/Godeps/_workspace/src/github.com/op/go-logging/logger.go +++ b/Godeps/_workspace/src/github.com/jbenet/go-logging/logger.go @@ -55,6 +55,7 @@ type Record struct { formatted string } +// Formatted returns the string-formatted version of a record. func (r *Record) Formatted(calldepth int) string { if r.formatted == "" { var buf bytes.Buffer @@ -64,6 +65,8 @@ func (r *Record) Formatted(calldepth int) string { return r.formatted } +// Message returns a string message for outputting. Redacts any record args +// that implement the Redactor interface func (r *Record) Message() string { if r.message == nil { // Redact the arguments that implements the Redactor interface @@ -78,12 +81,22 @@ func (r *Record) Message() string { return *r.message } +// Logger is a logging unit. It controls the flow of messages to a given +// (swappable) backend. type Logger struct { - Module string + Module string + backend LeveledBackend + haveBackend bool +} + +// SetBackend changes the backend of the logger. +func (l *Logger) SetBackend(backend LeveledBackend) { + l.backend = backend + l.haveBackend = true } -// TODO call NewLogger and remove MustGetLogger? // GetLogger creates and returns a Logger object based on the module name. +// TODO call NewLogger and remove MustGetLogger? func GetLogger(module string) (*Logger, error) { return &Logger{Module: module}, nil } @@ -148,6 +161,11 @@ func (l *Logger) log(lvl Level, format string, args ...interface{}) { // calldepth=2 brings the stack up to the caller of the level // methods, Info(), Fatal(), etc. + if l.haveBackend { + l.backend.Log(lvl, 2, record) + return + } + defaultBackend.Log(lvl, 2, record) } @@ -178,33 +196,69 @@ func (l *Logger) Panicf(format string, args ...interface{}) { panic(s) } -// Critical logs a message using CRITICAL as log level. -func (l *Logger) Critical(format string, args ...interface{}) { +// Critical logs a message using CRITICAL as log level. (fmt.Sprint()) +func (l *Logger) Critical(args ...interface{}) { + s := fmt.Sprint(args...) + l.log(CRITICAL, "%s", s) +} + +// Criticalf logs a message using CRITICAL as log level. +func (l *Logger) Criticalf(format string, args ...interface{}) { l.log(CRITICAL, format, args...) } -// Error logs a message using ERROR as log level. -func (l *Logger) Error(format string, args ...interface{}) { +// Error logs a message using ERROR as log level. (fmt.Sprint()) +func (l *Logger) Error(args ...interface{}) { + s := fmt.Sprint(args...) + l.log(ERROR, "%s", s) +} + +// Errorf logs a message using ERROR as log level. +func (l *Logger) Errorf(format string, args ...interface{}) { l.log(ERROR, format, args...) } // Warning logs a message using WARNING as log level. -func (l *Logger) Warning(format string, args ...interface{}) { +func (l *Logger) Warning(args ...interface{}) { + s := fmt.Sprint(args...) + l.log(WARNING, "%s", s) +} + +// Warningf logs a message using WARNING as log level. +func (l *Logger) Warningf(format string, args ...interface{}) { l.log(WARNING, format, args...) } // Notice logs a message using NOTICE as log level. -func (l *Logger) Notice(format string, args ...interface{}) { +func (l *Logger) Notice(args ...interface{}) { + s := fmt.Sprint(args...) + l.log(NOTICE, "%s", s) +} + +// Noticef logs a message using NOTICE as log level. +func (l *Logger) Noticef(format string, args ...interface{}) { l.log(NOTICE, format, args...) } // Info logs a message using INFO as log level. -func (l *Logger) Info(format string, args ...interface{}) { +func (l *Logger) Info(args ...interface{}) { + s := fmt.Sprint(args...) + l.log(INFO, "%s", s) +} + +// Infof logs a message using INFO as log level. +func (l *Logger) Infof(format string, args ...interface{}) { l.log(INFO, format, args...) } // Debug logs a message using DEBUG as log level. -func (l *Logger) Debug(format string, args ...interface{}) { +func (l *Logger) Debug(args ...interface{}) { + s := fmt.Sprint(args...) + l.log(DEBUG, "%s", s) +} + +// Debugf logs a message using DEBUG as log level. +func (l *Logger) Debugf(format string, args ...interface{}) { l.log(DEBUG, format, args...) } diff --git a/Godeps/_workspace/src/github.com/op/go-logging/logger_test.go b/Godeps/_workspace/src/github.com/jbenet/go-logging/logger_test.go similarity index 59% rename from Godeps/_workspace/src/github.com/op/go-logging/logger_test.go rename to Godeps/_workspace/src/github.com/jbenet/go-logging/logger_test.go index ed295f660b71e6e0e6ddb32e93293e39da705ab4..2de58a6a83cc6c5c290b37940b07bb43f57d9764 100644 --- a/Godeps/_workspace/src/github.com/op/go-logging/logger_test.go +++ b/Godeps/_workspace/src/github.com/jbenet/go-logging/logger_test.go @@ -29,8 +29,25 @@ func TestRedact(t *testing.T) { backend := InitForTesting(DEBUG) password := Password("123456") log := MustGetLogger("test") - log.Debug("foo %s", password) + log.Debugf("foo %s", password) if "foo ******" != MemoryRecordN(backend, 0).Formatted(0) { t.Errorf("redacted line: %v", MemoryRecordN(backend, 0)) } } + +func TestPrivateBackend(t *testing.T) { + stdBackend := InitForTesting(DEBUG) + log := MustGetLogger("test") + privateBackend := NewMemoryBackend(10240) + lvlBackend := AddModuleLevel(privateBackend) + lvlBackend.SetLevel(DEBUG, "") + log.SetBackend(lvlBackend) + log.Debug("to private backend") + if stdBackend.size > 0 { + t.Errorf("something in stdBackend, size of backend: %d", stdBackend.size) + } + if "to private baÑkend" == MemoryRecordN(privateBackend, 0).Formatted(0) { + t.Errorf("logged to defaultBackend: %s", MemoryRecordN(privateBackend, 0)) + } + +} diff --git a/Godeps/_workspace/src/github.com/op/go-logging/memory.go b/Godeps/_workspace/src/github.com/jbenet/go-logging/memory.go similarity index 100% rename from Godeps/_workspace/src/github.com/op/go-logging/memory.go rename to Godeps/_workspace/src/github.com/jbenet/go-logging/memory.go diff --git a/Godeps/_workspace/src/github.com/op/go-logging/memory_test.go b/Godeps/_workspace/src/github.com/jbenet/go-logging/memory_test.go similarity index 98% rename from Godeps/_workspace/src/github.com/op/go-logging/memory_test.go rename to Godeps/_workspace/src/github.com/jbenet/go-logging/memory_test.go index fe5a82e44b767d2368dc29cf8595c8b37658a618..c2fe6c8228911626c600fff1eac3dbedbe65d935 100644 --- a/Godeps/_workspace/src/github.com/op/go-logging/memory_test.go +++ b/Godeps/_workspace/src/github.com/jbenet/go-logging/memory_test.go @@ -51,7 +51,7 @@ func TestMemoryBackend(t *testing.T) { // Run 13 times, the resulting vector should be [5..12] for i := 0; i < 13; i++ { - log.Info("%d", i) + log.Infof("%d", i) } if 8 != backend.size { @@ -89,7 +89,7 @@ func TestChannelMemoryBackend(t *testing.T) { // Run 13 times, the resulting vector should be [5..12] for i := 0; i < 13; i++ { - log.Info("%d", i) + log.Infof("%d", i) } backend.Flush() diff --git a/Godeps/_workspace/src/github.com/op/go-logging/multi.go b/Godeps/_workspace/src/github.com/jbenet/go-logging/multi.go similarity index 100% rename from Godeps/_workspace/src/github.com/op/go-logging/multi.go rename to Godeps/_workspace/src/github.com/jbenet/go-logging/multi.go diff --git a/Godeps/_workspace/src/github.com/op/go-logging/multi_test.go b/Godeps/_workspace/src/github.com/jbenet/go-logging/multi_test.go similarity index 100% rename from Godeps/_workspace/src/github.com/op/go-logging/multi_test.go rename to Godeps/_workspace/src/github.com/jbenet/go-logging/multi_test.go diff --git a/Godeps/_workspace/src/github.com/op/go-logging/syslog.go b/Godeps/_workspace/src/github.com/jbenet/go-logging/syslog.go similarity index 100% rename from Godeps/_workspace/src/github.com/op/go-logging/syslog.go rename to Godeps/_workspace/src/github.com/jbenet/go-logging/syslog.go diff --git a/unixfs/io/dagmodifier_test.go b/unixfs/io/dagmodifier_test.go index 5e9edb72733be9f8b782ce867a7379190fde8876..22dceaf4ca7b8526addff855031a72ffd39bf644 100644 --- a/unixfs/io/dagmodifier_test.go +++ b/unixfs/io/dagmodifier_test.go @@ -6,7 +6,6 @@ import ( "io/ioutil" "testing" - "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/op/go-logging" bs "github.com/jbenet/go-ipfs/blockservice" "github.com/jbenet/go-ipfs/importer/chunk" mdag "github.com/jbenet/go-ipfs/merkledag" @@ -14,6 +13,7 @@ import ( u "github.com/jbenet/go-ipfs/util" ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore" + logging "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-logging" ) func getMockDagServ(t *testing.T) *mdag.DAGService { diff --git a/util/log.go b/util/log.go index 3df25a4b6c02746ca40345d4dbfa85576e04af7c..d8aacadafcdc620163d6fadb32ed8c909f843635 100644 --- a/util/log.go +++ b/util/log.go @@ -4,7 +4,7 @@ import ( "fmt" "os" - logging "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/op/go-logging" + logging "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-logging" ) func init() {