From 6fe9b4ab5e839be96eb1c4a619bc14fab622d8d1 Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Mon, 7 Jul 2014 10:59:16 +0200 Subject: Revert "ethreact - Feature/ethutil refactor" --- ethlog/loggers.go | 57 ++++++++++++++++++------------------------------------- 1 file changed, 18 insertions(+), 39 deletions(-) (limited to 'ethlog/loggers.go') diff --git a/ethlog/loggers.go b/ethlog/loggers.go index d7707cf9e..219c78240 100644 --- a/ethlog/loggers.go +++ b/ethlog/loggers.go @@ -40,9 +40,6 @@ func (msg *logMessage) send(logger LogSystem) { var logMessages chan (*logMessage) var logSystems []LogSystem var quit chan bool -var drained chan bool -var shutdown chan bool -var mutex = sync.Mutex{} type LogLevel uint8 @@ -60,41 +57,29 @@ func start() { out: for { select { - case <-quit: - break out case msg := <-logMessages: for _, logSystem := range logSystems { if logSystem.GetLogLevel() >= msg.LogLevel { msg.send(logSystem) } } - case drained <- true: - default: - drained <- true // this blocks until a message is sent to the queu - } - } - close(shutdown) -} - -func Reset() { - mutex.Lock() - defer mutex.Unlock() - if logSystems != nil { - quit <- true - select { - case <-drained: + case <-quit: + break out } - <-shutdown } - logSystems = nil } // waits until log messages are drained (dispatched to log writers) func Flush() { - mutex.Lock() - defer mutex.Unlock() - if logSystems != nil { - <-drained + quit <- true + +done: + for { + select { + case <-logMessages: + default: + break done + } } } @@ -107,34 +92,28 @@ func NewLogger(tag string) *Logger { } func AddLogSystem(logSystem LogSystem) { + var mutex = &sync.Mutex{} mutex.Lock() defer mutex.Unlock() if logSystems == nil { logMessages = make(chan *logMessage) quit = make(chan bool) - drained = make(chan bool, 1) - shutdown = make(chan bool, 1) go start() } logSystems = append(logSystems, logSystem) } -func send(msg *logMessage) { - select { - case <-drained: - } - logMessages <- msg -} - 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 } } -- cgit From e4e704f48074161a175cc125c5fabdf94c095ca8 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 7 Jul 2014 16:05:59 +0200 Subject: Fix quit --- ethlog/loggers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethlog/loggers.go') diff --git a/ethlog/loggers.go b/ethlog/loggers.go index 219c78240..ec481edd8 100644 --- a/ethlog/loggers.go +++ b/ethlog/loggers.go @@ -97,7 +97,7 @@ func AddLogSystem(logSystem LogSystem) { defer mutex.Unlock() if logSystems == nil { logMessages = make(chan *logMessage) - quit = make(chan bool) + quit = make(chan bool, 1) go start() } logSystems = append(logSystems, logSystem) -- cgit