aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-07-05 19:24:26 +0800
committerobscuren <geffobscura@gmail.com>2014-07-05 19:24:26 +0800
commit329887df993aefc8799cf64ed20cf1dcc8cfb6ed (patch)
treeb4c728e35772cb3ab92a808a577f438ce4ad4756
parent90eb4f1939f7b0389d5784b889cc0e5d2b3451f7 (diff)
downloaddexon-329887df993aefc8799cf64ed20cf1dcc8cfb6ed.tar
dexon-329887df993aefc8799cf64ed20cf1dcc8cfb6ed.tar.gz
dexon-329887df993aefc8799cf64ed20cf1dcc8cfb6ed.tar.bz2
dexon-329887df993aefc8799cf64ed20cf1dcc8cfb6ed.tar.lz
dexon-329887df993aefc8799cf64ed20cf1dcc8cfb6ed.tar.xz
dexon-329887df993aefc8799cf64ed20cf1dcc8cfb6ed.tar.zst
dexon-329887df993aefc8799cf64ed20cf1dcc8cfb6ed.zip
Fixed crazy looping
-rw-r--r--ethlog/loggers.go20
1 files changed, 14 insertions, 6 deletions
diff --git a/ethlog/loggers.go b/ethlog/loggers.go
index 9ebe59096..219c78240 100644
--- a/ethlog/loggers.go
+++ b/ethlog/loggers.go
@@ -39,7 +39,7 @@ func (msg *logMessage) send(logger LogSystem) {
var logMessages chan (*logMessage)
var logSystems []LogSystem
-var drained = true
+var quit chan bool
type LogLevel uint8
@@ -54,6 +54,7 @@ const (
// log messages are dispatched to log writers
func start() {
+out:
for {
select {
case msg := <-logMessages:
@@ -62,15 +63,23 @@ func start() {
msg.send(logSystem)
}
}
- default:
- drained = true
+ case <-quit:
+ break out
}
}
}
// waits until log messages are drained (dispatched to log writers)
func Flush() {
- for !drained {
+ quit <- true
+
+done:
+ for {
+ select {
+ case <-logMessages:
+ default:
+ break done
+ }
}
}
@@ -88,6 +97,7 @@ func AddLogSystem(logSystem LogSystem) {
defer mutex.Unlock()
if logSystems == nil {
logMessages = make(chan *logMessage)
+ quit = make(chan bool)
go start()
}
logSystems = append(logSystems, logSystem)
@@ -96,7 +106,6 @@ func AddLogSystem(logSystem LogSystem) {
func (logger *Logger) sendln(level LogLevel, v ...interface{}) {
if logMessages != nil {
msg := newPrintlnLogMessage(level, logger.tag, v...)
- drained = false
logMessages <- msg
}
}
@@ -104,7 +113,6 @@ func (logger *Logger) sendln(level LogLevel, v ...interface{}) {
func (logger *Logger) sendf(level LogLevel, format string, v ...interface{}) {
if logMessages != nil {
msg := newPrintfLogMessage(level, logger.tag, format, v...)
- drained = false
logMessages <- msg
}
}