From 210b5df78c4c8003bab3dca6995aa88fe6b7287f Mon Sep 17 00:00:00 2001
From: Juan Batiz-Benet <juan@benet.ai>
Date: Sat, 25 Oct 2014 02:50:13 -0700
Subject: [PATCH] use my go-logging fork

until https://github.com/op/go-logging/pull/30 is merged
---
 Godeps/Godeps.json                            |   8 +-
 .../{op => jbenet}/go-logging/.travis.yml     |   0
 .../{op => jbenet}/go-logging/CONTRIBUTORS    |   0
 .../{op => jbenet}/go-logging/LICENSE         |   0
 .../{op => jbenet}/go-logging/README.md       |   1 -
 .../{op => jbenet}/go-logging/backend.go      |   0
 .../go-logging/examples/example.go            |   2 +-
 .../go-logging/examples/example.png           | Bin
 .../{op => jbenet}/go-logging/format.go       |   0
 .../{op => jbenet}/go-logging/format_test.go  |   0
 .../{op => jbenet}/go-logging/level.go        |   0
 .../{op => jbenet}/go-logging/level_test.go   |   0
 .../{op => jbenet}/go-logging/log.go          |   0
 .../{op => jbenet}/go-logging/log_test.go     |   0
 .../{op => jbenet}/go-logging/logger.go       |  74 +++++++++++++++---
 .../{op => jbenet}/go-logging/logger_test.go  |  19 ++++-
 .../{op => jbenet}/go-logging/memory.go       |   0
 .../{op => jbenet}/go-logging/memory_test.go  |   4 +-
 .../{op => jbenet}/go-logging/multi.go        |   0
 .../{op => jbenet}/go-logging/multi_test.go   |   0
 .../{op => jbenet}/go-logging/syslog.go       |   0
 unixfs/io/dagmodifier_test.go                 |   2 +-
 util/log.go                                   |   2 +-
 23 files changed, 91 insertions(+), 21 deletions(-)
 rename Godeps/_workspace/src/github.com/{op => jbenet}/go-logging/.travis.yml (100%)
 rename Godeps/_workspace/src/github.com/{op => jbenet}/go-logging/CONTRIBUTORS (100%)
 rename Godeps/_workspace/src/github.com/{op => jbenet}/go-logging/LICENSE (100%)
 rename Godeps/_workspace/src/github.com/{op => jbenet}/go-logging/README.md (99%)
 rename Godeps/_workspace/src/github.com/{op => jbenet}/go-logging/backend.go (100%)
 rename Godeps/_workspace/src/github.com/{op => jbenet}/go-logging/examples/example.go (94%)
 rename Godeps/_workspace/src/github.com/{op => jbenet}/go-logging/examples/example.png (100%)
 rename Godeps/_workspace/src/github.com/{op => jbenet}/go-logging/format.go (100%)
 rename Godeps/_workspace/src/github.com/{op => jbenet}/go-logging/format_test.go (100%)
 rename Godeps/_workspace/src/github.com/{op => jbenet}/go-logging/level.go (100%)
 rename Godeps/_workspace/src/github.com/{op => jbenet}/go-logging/level_test.go (100%)
 rename Godeps/_workspace/src/github.com/{op => jbenet}/go-logging/log.go (100%)
 rename Godeps/_workspace/src/github.com/{op => jbenet}/go-logging/log_test.go (100%)
 rename Godeps/_workspace/src/github.com/{op => jbenet}/go-logging/logger.go (73%)
 rename Godeps/_workspace/src/github.com/{op => jbenet}/go-logging/logger_test.go (59%)
 rename Godeps/_workspace/src/github.com/{op => jbenet}/go-logging/memory.go (100%)
 rename Godeps/_workspace/src/github.com/{op => jbenet}/go-logging/memory_test.go (98%)
 rename Godeps/_workspace/src/github.com/{op => jbenet}/go-logging/multi.go (100%)
 rename Godeps/_workspace/src/github.com/{op => jbenet}/go-logging/multi_test.go (100%)
 rename Godeps/_workspace/src/github.com/{op => jbenet}/go-logging/syslog.go (100%)

diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json
index e8c83f96b..3bbcd876e 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 81d1705fc..ec5cf2405 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 58287ad0a..28168d00e 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 47bbd444b..867916dbf 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 ed295f660..2de58a6a8 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 fe5a82e44..c2fe6c822 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 5e9edb727..22dceaf4c 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 3df25a4b6..d8aacadaf 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() {
-- 
GitLab