-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplates.go
More file actions
40 lines (33 loc) · 1.18 KB
/
templates.go
File metadata and controls
40 lines (33 loc) · 1.18 KB
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
package gomolconsole
import "github.com/aphistic/gomol"
/*
NewTemplateDefault will create a new default logging template.
Example output:
[INFO] This is my message
*/
func NewTemplateDefault() *gomol.Template {
tpl, _ := gomol.NewTemplate("[{{color}}{{ucase .LevelName}}{{reset}}] {{.Message}}")
return tpl
}
/*
NewTemplateTimestamped will create a new logging template including the current timestamp.
Example output:
2006-01-02 15:04:05.000 [INFO] This is my message
*/
func NewTemplateTimestamped() *gomol.Template {
tpl, _ := gomol.NewTemplate("{{.Timestamp.Format \"2006-01-02 15:04:05.000\"}} [{{color}}{{ucase .LevelName}}{{reset}}] {{.Message}}")
return tpl
}
/*
NewTemplateFull will create a new logging template including the current timestamp as well as any
attributes included with the message.
Example output:
2006-01-02 15:04:05.000 [INFO] This is my message
attr1: 1234
attr2: value2
*/
func NewTemplateFull() *gomol.Template {
tpl, _ := gomol.NewTemplate("{{.Timestamp.Format \"2006-01-02 15:04:05.000\"}} [{{color}}{{ucase .LevelName}}{{reset}}] {{.Message}}" +
"{{if .Attrs}}{{range $key, $val := .Attrs}}\n {{$key}}: {{$val}}{{end}}{{end}}")
return tpl
}