Skip to content
Snippets Groups Projects
Unverified Commit 8a1708f0 authored by Silas Davis's avatar Silas Davis
Browse files

document structure a bit better

parent cb1ffca5
No related branches found
No related tags found
No related merge requests found
......@@ -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
}
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment