/
adapter.go
49 lines (43 loc) · 893 Bytes
/
adapter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package log4go
import (
"strings"
)
// template 模版适配器
const (
t = 0x00000001
d = 0x00000010
l = 0x00000100
s = 0x00001000
m = 0x00010000
)
var (
options = map[string]int64{
"%T": t,
"%D": d,
"%L": l,
"%S": s,
"%M": m,
}
adapter = strings.NewReplacer(
"%T", "{{if .TIME}}{{.TIME.Format \"15:04:05\"}}{{end}}",
"%D", "{{if .TIME}}{{.TIME.Format \"2006-01-02\"}}{{end}}",
"%L", "{{.LEVEL}}",
"%S", "{{.SOURCE}}",
"%M", "{{.MESSAGE}}",
)
)
// 配置文件格式
type xmlProperty struct {
Name string `xml:"name,attr"`
Value string `xml:",chardata"`
}
type xmlFilter struct {
Enabled bool `xml:"enabled,attr"`
Type string `xml:"type"`
Level string `xml:"level"`
Property []xmlProperty `xml:"property"`
}
type xmlLoggerConfig struct {
Filter []xmlFilter `xml:"filter"`
Unmerge bool `xml:"unmerge,attr"`
}