From 7f9c3354872e6fcc63c37abddb184e3e58790bc3 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 21 Jan 2015 10:04:11 -0600 Subject: Split into multiple files --- logger/loggers.go | 122 ------------------------------------------------------ 1 file changed, 122 deletions(-) (limited to 'logger/loggers.go') diff --git a/logger/loggers.go b/logger/loggers.go index 1bf7bfa0e..de9dfc095 100644 --- a/logger/loggers.go +++ b/logger/loggers.go @@ -14,11 +14,7 @@ package logger import ( "fmt" - "io" - "log" "os" - "sync" - "sync/atomic" ) // LogSystem is implemented by log output devices. @@ -46,100 +42,6 @@ const ( DebugDetailLevel ) -var ( - logMessageC = make(chan message) - addSystemC = make(chan LogSystem) - flushC = make(chan chan struct{}) - resetC = make(chan chan struct{}) -) - -func init() { - go dispatchLoop() -} - -// each system can buffer this many messages before -// blocking incoming log messages. -const sysBufferSize = 500 - -func dispatchLoop() { - var ( - systems []LogSystem - systemIn []chan message - systemWG sync.WaitGroup - ) - bootSystem := func(sys LogSystem) { - in := make(chan message, sysBufferSize) - systemIn = append(systemIn, in) - systemWG.Add(1) - go sysLoop(sys, in, &systemWG) - } - - for { - select { - case msg := <-logMessageC: - for _, c := range systemIn { - c <- msg - } - - case sys := <-addSystemC: - systems = append(systems, sys) - bootSystem(sys) - - case waiter := <-resetC: - // reset means terminate all systems - for _, c := range systemIn { - close(c) - } - systems = nil - systemIn = nil - systemWG.Wait() - close(waiter) - - case waiter := <-flushC: - // flush means reboot all systems - for _, c := range systemIn { - close(c) - } - systemIn = nil - systemWG.Wait() - for _, sys := range systems { - bootSystem(sys) - } - close(waiter) - } - } -} - -func sysLoop(sys LogSystem, in <-chan message, wg *sync.WaitGroup) { - for msg := range in { - if sys.GetLogLevel() >= msg.level { - sys.LogPrint(msg.level, msg.msg) - } - } - wg.Done() -} - -// Reset removes all active log systems. -// It blocks until all current messages have been delivered. -func Reset() { - waiter := make(chan struct{}) - resetC <- waiter - <-waiter -} - -// Flush waits until all current log messages have been dispatched to -// the active log systems. -func Flush() { - waiter := make(chan struct{}) - flushC <- waiter - <-waiter -} - -// AddLogSystem starts printing messages to the given LogSystem. -func AddLogSystem(sys LogSystem) { - addSystemC <- sys -} - // A Logger prints messages prefixed by a given tag. It provides named // Printf and Println style methods for all loglevels. Each ethereum // component should have its own logger with a unique prefix. @@ -222,27 +124,3 @@ func (logger *Logger) Fatalf(format string, v ...interface{}) { Flush() os.Exit(0) } - -// NewStdLogSystem creates a LogSystem that prints to the given writer. -// The flag values are defined package log. -func NewStdLogSystem(writer io.Writer, flags int, level LogLevel) LogSystem { - logger := log.New(writer, "", flags) - return &stdLogSystem{logger, uint32(level)} -} - -type stdLogSystem struct { - logger *log.Logger - level uint32 -} - -func (t *stdLogSystem) LogPrint(level LogLevel, msg string) { - t.logger.Print(msg) -} - -func (t *stdLogSystem) SetLogLevel(i LogLevel) { - atomic.StoreUint32(&t.level, uint32(i)) -} - -func (t *stdLogSystem) GetLogLevel() LogLevel { - return LogLevel(atomic.LoadUint32(&t.level)) -} -- cgit From 41d80ba17bac2d6cfefb8a1c6206fe1ccee04d1d Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 21 Jan 2015 10:18:46 -0600 Subject: Add JsonLevel log level --- logger/loggers.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'logger/loggers.go') diff --git a/logger/loggers.go b/logger/loggers.go index de9dfc095..497060fdb 100644 --- a/logger/loggers.go +++ b/logger/loggers.go @@ -30,7 +30,7 @@ type message struct { msg string } -type LogLevel uint8 +type LogLevel uint32 const ( // Standard log levels @@ -40,6 +40,7 @@ const ( InfoLevel DebugLevel DebugDetailLevel + JsonLevel = 1000 ) // A Logger prints messages prefixed by a given tag. It provides named -- cgit From ed7d7b405e1de8010f2ddeecf2b3798e2f07ad31 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 21 Jan 2015 10:26:54 -0600 Subject: Split file cleanup --- logger/loggers.go | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'logger/loggers.go') diff --git a/logger/loggers.go b/logger/loggers.go index 497060fdb..77d111974 100644 --- a/logger/loggers.go +++ b/logger/loggers.go @@ -17,19 +17,6 @@ import ( "os" ) -// LogSystem is implemented by log output devices. -// All methods can be called concurrently from multiple goroutines. -type LogSystem interface { - GetLogLevel() LogLevel - SetLogLevel(i LogLevel) - LogPrint(LogLevel, string) -} - -type message struct { - level LogLevel - msg string -} - type LogLevel uint32 const ( -- cgit From 1077109e1153cc4fb4eece59dd48cd9f640d0e0b Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 21 Jan 2015 10:57:29 -0600 Subject: Add JsonLogger type --- logger/loggers.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'logger/loggers.go') diff --git a/logger/loggers.go b/logger/loggers.go index 77d111974..053f120be 100644 --- a/logger/loggers.go +++ b/logger/loggers.go @@ -13,8 +13,10 @@ logging of mutable state. package logger import ( + "encoding/json" "fmt" "os" + "time" ) type LogLevel uint32 @@ -112,3 +114,27 @@ func (logger *Logger) Fatalf(format string, v ...interface{}) { Flush() os.Exit(0) } + +type JsonLogger struct{} + +func NewJsonLogger() *JsonLogger { + return &JsonLogger{} +} + +func (logger *JsonLogger) Log(msgname string, dict map[string]interface{}) { + if _, ok := dict["ts"]; !ok { + dict["ts"] = time.Now().Local().Format(time.RFC3339Nano) + } + + // FIX + if _, ok := dict["level"]; !ok { + dict["level"] = "debug" + } + + obj := map[string]interface{}{ + msgname: dict, + } + + jsontxt, _ := json.Marshal(obj) + logMessageC <- message{JsonLevel, fmt.Sprintf("%s", jsontxt)} +} -- cgit From 0aa76d3e5b3eb261103ebf5afd515394df0af914 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 21 Jan 2015 11:45:30 -0600 Subject: Rename jsonlogger method --- logger/loggers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'logger/loggers.go') diff --git a/logger/loggers.go b/logger/loggers.go index 053f120be..cd465ce87 100644 --- a/logger/loggers.go +++ b/logger/loggers.go @@ -121,7 +121,7 @@ func NewJsonLogger() *JsonLogger { return &JsonLogger{} } -func (logger *JsonLogger) Log(msgname string, dict map[string]interface{}) { +func (logger *JsonLogger) LogJson(msgname string, dict map[string]interface{}) { if _, ok := dict["ts"]; !ok { dict["ts"] = time.Now().Local().Format(time.RFC3339Nano) } -- cgit From d53e5646ecfce75790fea45a1ee552494ef88668 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Tue, 10 Feb 2015 19:21:13 +0100 Subject: Use strongly-typed objects --- logger/loggers.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'logger/loggers.go') diff --git a/logger/loggers.go b/logger/loggers.go index cd465ce87..36bc38116 100644 --- a/logger/loggers.go +++ b/logger/loggers.go @@ -16,7 +16,6 @@ import ( "encoding/json" "fmt" "os" - "time" ) type LogLevel uint32 @@ -121,20 +120,12 @@ func NewJsonLogger() *JsonLogger { return &JsonLogger{} } -func (logger *JsonLogger) LogJson(msgname string, dict map[string]interface{}) { - if _, ok := dict["ts"]; !ok { - dict["ts"] = time.Now().Local().Format(time.RFC3339Nano) - } - - // FIX - if _, ok := dict["level"]; !ok { - dict["level"] = "debug" - } - +func (logger *JsonLogger) LogJson(msgname string, v interface{}) { obj := map[string]interface{}{ - msgname: dict, + msgname: v, } jsontxt, _ := json.Marshal(obj) - logMessageC <- message{JsonLevel, fmt.Sprintf("%s", jsontxt)} + logMessageC <- message{JsonLevel, string(jsontxt)} + } -- cgit From 3d6fd601c5eec13480b6c736f6811b663a885766 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 11 Feb 2015 12:45:41 +0100 Subject: Move event names within each object --- logger/loggers.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'logger/loggers.go') diff --git a/logger/loggers.go b/logger/loggers.go index 36bc38116..fd2a01dfd 100644 --- a/logger/loggers.go +++ b/logger/loggers.go @@ -120,7 +120,8 @@ func NewJsonLogger() *JsonLogger { return &JsonLogger{} } -func (logger *JsonLogger) LogJson(msgname string, v interface{}) { +func (logger *JsonLogger) LogJson(v LogEvent) { + msgname := v.EventName() obj := map[string]interface{}{ msgname: v, } -- cgit From db24fb792cf0dab91bc85e79aecf6758349002a4 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 11 Feb 2015 18:49:00 +0100 Subject: Move standard fields to LogEvent --- logger/loggers.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'logger/loggers.go') diff --git a/logger/loggers.go b/logger/loggers.go index fd2a01dfd..147b2b85f 100644 --- a/logger/loggers.go +++ b/logger/loggers.go @@ -114,13 +114,15 @@ func (logger *Logger) Fatalf(format string, v ...interface{}) { os.Exit(0) } -type JsonLogger struct{} +type JsonLogger struct { + Coinbase string +} func NewJsonLogger() *JsonLogger { return &JsonLogger{} } -func (logger *JsonLogger) LogJson(v LogEvent) { +func (logger *JsonLogger) LogJson(v JsonLog) { msgname := v.EventName() obj := map[string]interface{}{ msgname: v, -- cgit