diff options
author | zelig <viktor.tron@gmail.com> | 2015-03-21 17:20:47 +0800 |
---|---|---|
committer | zelig <viktor.tron@gmail.com> | 2015-03-22 10:16:54 +0800 |
commit | 78cff9e3a4c71d003c5ab3f5747ccae1dbc959fe (patch) | |
tree | 0bdc1bb55b9bd73730f9de658e1d87273482761a /logger/sys.go | |
parent | 7f85608f30a2e34005c8d15566849229c758c2f1 (diff) | |
download | go-tangerine-78cff9e3a4c71d003c5ab3f5747ccae1dbc959fe.tar go-tangerine-78cff9e3a4c71d003c5ab3f5747ccae1dbc959fe.tar.gz go-tangerine-78cff9e3a4c71d003c5ab3f5747ccae1dbc959fe.tar.bz2 go-tangerine-78cff9e3a4c71d003c5ab3f5747ccae1dbc959fe.tar.lz go-tangerine-78cff9e3a4c71d003c5ab3f5747ccae1dbc959fe.tar.xz go-tangerine-78cff9e3a4c71d003c5ab3f5747ccae1dbc959fe.tar.zst go-tangerine-78cff9e3a4c71d003c5ab3f5747ccae1dbc959fe.zip |
independent flag for json structured logging
- logjson flag remove logformat flag
- passed to eth Config
- logsystem not a field of Ethereum
- LogSystem does not need to expose GetLogLevel/SetLogLevel
- message struct just implements more generic LogMsg interface
- LogMsg is a fmt.Stringer with Level()
- jsonMsg ([]byte) implements LogMsg
- remove "raw" systems
- move level logic inside StdLogSystem
- logsystems only print their kind of msg: jsonLogSystem prints jsonMsg, StdLogSystem prints stdMsg
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() } |