aboutsummaryrefslogtreecommitdiffstats
path: root/logger
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-01-22 00:57:29 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-01-22 00:57:29 +0800
commit1077109e1153cc4fb4eece59dd48cd9f640d0e0b (patch)
tree6a1c748702dfb5a78071d16c2185fca33b16aa42 /logger
parented7d7b405e1de8010f2ddeecf2b3798e2f07ad31 (diff)
downloadgo-tangerine-1077109e1153cc4fb4eece59dd48cd9f640d0e0b.tar
go-tangerine-1077109e1153cc4fb4eece59dd48cd9f640d0e0b.tar.gz
go-tangerine-1077109e1153cc4fb4eece59dd48cd9f640d0e0b.tar.bz2
go-tangerine-1077109e1153cc4fb4eece59dd48cd9f640d0e0b.tar.lz
go-tangerine-1077109e1153cc4fb4eece59dd48cd9f640d0e0b.tar.xz
go-tangerine-1077109e1153cc4fb4eece59dd48cd9f640d0e0b.tar.zst
go-tangerine-1077109e1153cc4fb4eece59dd48cd9f640d0e0b.zip
Add JsonLogger type
Diffstat (limited to 'logger')
-rw-r--r--logger/loggers.go26
1 files changed, 26 insertions, 0 deletions
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)}
+}