-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
66 lines (53 loc) · 1.17 KB
/
logger.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"time"
)
type Logger struct {
in *log.Logger
}
type Entry struct {
Time string `json:"time"`
Severity string `json:"severity"`
Message string `json:"message"`
}
var logger = &Logger{
in: log.New(os.Stdout, "", 0),
}
func (l *Logger) Error(msg string) {
l.Write("ERROR", msg)
}
func (l *Logger) Errorf(format string, a ...interface{}) {
l.Write("ERROR", fmt.Sprintf(format, a...))
}
func (l *Logger) Warning(msg string) {
l.Write("WARNING", msg)
}
func (l *Logger) Warningf(format string, a ...interface{}) {
l.Write("WARNING", fmt.Sprintf(format, a...))
}
func (l *Logger) Info(msg string) {
l.Write("INFO", msg)
}
func (l *Logger) Infof(format string, a ...interface{}) {
l.Write("INFO", fmt.Sprintf(format, a...))
}
func (l *Logger) Debug(msg string) {
l.Write("DEBUG", msg)
}
func (l *Logger) Debugf(format string, a ...interface{}) {
l.Write("DEBUG", fmt.Sprintf(format, a...))
}
func (l *Logger) Write(severity, msg string) {
now := time.Now().Format(time.RFC3339Nano)
entry := Entry{
Time: now,
Severity: severity,
Message: msg,
}
b, _ := json.Marshal(entry)
l.in.Print(string(b))
}