diff options
author | obscuren <geffobscura@gmail.com> | 2015-03-23 04:43:36 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-03-23 04:43:36 +0800 |
commit | 8b1b9fc99d63a19c216edebc07096718e835937d (patch) | |
tree | 8a04499cb63dd8d91fd136f65c29605844c5bae8 /logger/sys.go | |
parent | 8ed4f226d1dbecc9625a2f142e22926569198b73 (diff) | |
parent | 0edb33566fbe20863c884e553e214ed9b78b0f23 (diff) | |
download | go-tangerine-8b1b9fc99d63a19c216edebc07096718e835937d.tar go-tangerine-8b1b9fc99d63a19c216edebc07096718e835937d.tar.gz go-tangerine-8b1b9fc99d63a19c216edebc07096718e835937d.tar.bz2 go-tangerine-8b1b9fc99d63a19c216edebc07096718e835937d.tar.lz go-tangerine-8b1b9fc99d63a19c216edebc07096718e835937d.tar.xz go-tangerine-8b1b9fc99d63a19c216edebc07096718e835937d.tar.zst go-tangerine-8b1b9fc99d63a19c216edebc07096718e835937d.zip |
Merge branch 'jsonlog' of https://github.com/ethersphere/go-ethereum into ethersphere-jsonlog
Conflicts:
eth/backend.go
Diffstat (limited to 'logger/sys.go')
-rw-r--r-- | logger/sys.go | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/logger/sys.go b/logger/sys.go index db4251a52..c4d5c382a 100644 --- a/logger/sys.go +++ b/logger/sys.go @@ -1,16 +1,40 @@ package logger import ( + "fmt" "sync" ) -type message struct { +type stdMsg struct { level LogLevel msg string } +type jsonMsg []byte + +func (m jsonMsg) Level() LogLevel { + return 0 +} + +func (m jsonMsg) String() string { + return string(m) +} + +type LogMsg interface { + Level() LogLevel + fmt.Stringer +} + +func (m stdMsg) Level() LogLevel { + return m.level +} + +func (m stdMsg) String() string { + return m.msg +} + var ( - logMessageC = make(chan message) + logMessageC = make(chan LogMsg) addSystemC = make(chan LogSystem) flushC = make(chan chan struct{}) resetC = make(chan chan struct{}) @@ -27,11 +51,11 @@ const sysBufferSize = 500 func dispatchLoop() { var ( systems []LogSystem - systemIn []chan message + systemIn []chan LogMsg systemWG sync.WaitGroup ) bootSystem := func(sys LogSystem) { - in := make(chan message, sysBufferSize) + in := make(chan LogMsg, sysBufferSize) systemIn = append(systemIn, in) systemWG.Add(1) go sysLoop(sys, in, &systemWG) @@ -73,18 +97,9 @@ func dispatchLoop() { } } -func sysLoop(sys LogSystem, in <-chan message, wg *sync.WaitGroup) { +func sysLoop(sys LogSystem, in <-chan LogMsg, wg *sync.WaitGroup) { for msg := range in { - switch sys.(type) { - case *jsonLogSystem: - if msg.level == JsonLevel { - sys.LogPrint(msg.level, msg.msg) - } - default: - if sys.GetLogLevel() >= msg.level { - sys.LogPrint(msg.level, msg.msg) - } - } + sys.LogPrint(msg) } wg.Done() } |