diff --git a/logging/adapters/tendermint_log15/convert.go b/logging/adapters/tendermint_log15/convert.go index f41e902373cd4e37ea8d71fd53b42bd45a318628..52cda465988566abeda50ac6ab28fad5c8a90838 100644 --- a/logging/adapters/tendermint_log15/convert.go +++ b/logging/adapters/tendermint_log15/convert.go @@ -3,26 +3,25 @@ package adapters import ( "time" + "github.com/eris-ltd/eris-db/logging/loggers" + "github.com/eris-ltd/eris-db/logging/structure" . "github.com/eris-ltd/eris-db/util/slice" "github.com/go-stack/stack" "github.com/tendermint/log15" - "github.com/eris-ltd/eris-db/logging/structure" - "github.com/eris-ltd/eris-db/logging/loggers" - "fmt" ) // Convert a go-kit log line (i.e. keyvals... interface{}) into a log15 record // This allows us to use log15 output handlers -func LogLineToRecord(keyvals... interface{}) *log15.Record { +func LogLineToRecord(keyvals ...interface{}) *log15.Record { vals, ctx := structure.ValuesAndContext(keyvals, structure.TimeKey, structure.MessageKey, structure.CallerKey, structure.LevelKey) + // Mapping of log line to Record is on a best effort basis theTime, _ := vals[structure.TimeKey].(time.Time) call, _ := vals[structure.CallerKey].(stack.Call) level, _ := vals[structure.LevelKey].(string) message, _ := vals[structure.MessageKey].(string) - fmt.Println(keyvals...) return &log15.Record{ Time: theTime, Lvl: Log15LvlFromString(level), @@ -68,4 +67,4 @@ func Log15LvlFromString(level string) log15.Lvl { } return log15.LvlDebug } -} \ No newline at end of file +} diff --git a/logging/structure/structure.go b/logging/structure/structure.go index 265300c328c134813c245dffb46fa1b68699a2c6..9420b20095b4fabab87ce707f082d17968f90ba3 100644 --- a/logging/structure/structure.go +++ b/logging/structure/structure.go @@ -9,15 +9,18 @@ const ( CallerKey = "caller" // Key for String name for level LevelKey = "level" + // Key to switch on for channel in a multiple channel logging context ChannelKey = "channel" - // String message key + // Key for string message MessageKey = "message" // Key for module or function or struct that is the subject of the logging ComponentKey = "component" ) // Pull the specified values from a structured log line into a map. -// Assumes keys are single-valued. And returns the rest as context. +// Assumes keys are single-valued. +// Returns a map of the key-values from the requested keys and +// the unmatched remainder keyvals as context as a slice of key-values. func ValuesAndContext(keyvals []interface{}, keys ...interface{}) (map[interface{}]interface{}, []interface{}) { vals := make(map[interface{}]interface{}, len(keys)) @@ -30,6 +33,7 @@ func ValuesAndContext(keyvals []interface{}, for i := 0; i < 2*(len(keyvals)/2); i += 2 { for k := 0; k < len(keys); k++ { if keyvals[i] == keys[k] { + // Pull the matching key-value pair into vals to return vals[keys[k]] = keyvals[i+1] // Delete the key once it's found keys = DeleteAt(keys, k)