aboutsummaryrefslogtreecommitdiffstats
path: root/ethlog
diff options
context:
space:
mode:
Diffstat (limited to 'ethlog')
-rw-r--r--ethlog/loggers.go12
-rw-r--r--ethlog/loggers_test.go12
2 files changed, 12 insertions, 12 deletions
diff --git a/ethlog/loggers.go b/ethlog/loggers.go
index 4e950cadd..f13186102 100644
--- a/ethlog/loggers.go
+++ b/ethlog/loggers.go
@@ -97,7 +97,6 @@ func Reset() {
}
<-status
}
- logSystems = nil
}
// waits until log messages are drained (dispatched to log writers)
@@ -116,6 +115,7 @@ func NewLogger(tag string) *Logger {
}
func AddLogSystem(logSystem LogSystem) {
+ var mutex = &sync.Mutex{}
mutex.Lock()
defer mutex.Unlock()
if logSystems == nil {
@@ -128,14 +128,16 @@ func AddLogSystem(logSystem LogSystem) {
}
func (logger *Logger) sendln(level LogLevel, v ...interface{}) {
- if logSystems != nil {
- send(newPrintlnLogMessage(level, logger.tag, v...))
+ if logMessages != nil {
+ msg := newPrintlnLogMessage(level, logger.tag, v...)
+ logMessages <- msg
}
}
func (logger *Logger) sendf(level LogLevel, format string, v ...interface{}) {
- if logSystems != nil {
- send(newPrintfLogMessage(level, logger.tag, format, v...))
+ if logMessages != nil {
+ msg := newPrintfLogMessage(level, logger.tag, format, v...)
+ logMessages <- msg
}
}
diff --git a/ethlog/loggers_test.go b/ethlog/loggers_test.go
index 0e1c12e55..a9b1463e7 100644
--- a/ethlog/loggers_test.go
+++ b/ethlog/loggers_test.go
@@ -54,8 +54,9 @@ func TestLoggerPrintln(t *testing.T) {
Flush()
Reset()
output := testLogSystem.Output
+ fmt.Println(quote(output))
if output != "[TEST] error\n[TEST] warn\n" {
- t.Error("Expected logger output '[TEST] error\\n[TEST] warn\\n', got ", testLogSystem.Output)
+ t.Error("Expected logger output '[TEST] error\\n[TEST] warn\\n', got ", output)
}
}
@@ -71,7 +72,7 @@ func TestLoggerPrintf(t *testing.T) {
Reset()
output := testLogSystem.Output
if output != "[TEST] error to { 2}\n[TEST] warn" {
- t.Error("Expected logger output '[TEST] error to { 2}\\n[TEST] warn', got ", testLogSystem.Output)
+ t.Error("Expected logger output '[TEST] error to { 2}\\n[TEST] warn', got ", output)
}
}
@@ -88,10 +89,10 @@ func TestMultipleLogSystems(t *testing.T) {
output0 := testLogSystem0.Output
output1 := testLogSystem1.Output
if output0 != "[TEST] error\n" {
- t.Error("Expected logger 0 output '[TEST] error\\n', got ", testLogSystem0.Output)
+ t.Error("Expected logger 0 output '[TEST] error\\n', got ", output0)
}
if output1 != "[TEST] error\n[TEST] warn\n" {
- t.Error("Expected logger 1 output '[TEST] error\\n[TEST] warn\\n', got ", testLogSystem1.Output)
+ t.Error("Expected logger 1 output '[TEST] error\\n[TEST] warn\\n', got ", output1)
}
}
@@ -104,7 +105,6 @@ func TestFileLogSystem(t *testing.T) {
logger.Errorf("error to %s\n", filename)
logger.Warnln("warn")
Flush()
- Reset()
contents, _ := ioutil.ReadFile(filename)
output := string(contents)
if output != "[TEST] error to test.log\n[TEST] warn\n" {
@@ -117,7 +117,5 @@ func TestFileLogSystem(t *testing.T) {
func TestNoLogSystem(t *testing.T) {
logger := NewLogger("TEST")
logger.Warnln("warn")
- fmt.Println("1")
Flush()
- Reset()
}