Use strongly-typed objects

This commit is contained in:
Taylor Gerring
2015-02-10 19:21:13 +01:00
parent c14900dbb0
commit d53e5646ec
4 changed files with 305 additions and 76 deletions

View File

@ -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)}
}