File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ package formatter
2+
3+ import (
4+ "encoding/json"
5+ "github.com/forgoer/thinkgo/log/record"
6+ )
7+
8+ type JsonFormatter struct {
9+ }
10+
11+ func NewJsonFormatter () * JsonFormatter {
12+ j := & JsonFormatter {}
13+ return j
14+ }
15+
16+ func (f * JsonFormatter ) Format (r record.Record ) string {
17+ normalized := make (map [string ]interface {})
18+
19+ normalized ["message" ] = r .Message
20+ normalized ["level" ] = r .Level
21+ normalized ["level_name" ] = r .LevelName
22+ normalized ["channel" ] = r .Channel
23+ normalized ["datetime" ] = r .Datetime .Local ().Format ("2006-01-02 15:04:05.000" )
24+
25+ output , _ := json .Marshal (normalized )
26+ return string (output ) + "\n "
27+ }
28+
29+ func (f * JsonFormatter ) FormatBatch (rs []record.Record ) string {
30+ message := ""
31+ for _ , r := range rs {
32+ message = message + f .Format (r )
33+ }
34+ return message
35+ }
You can’t perform that action at this time.
0 commit comments