-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
56 lines (44 loc) · 1.44 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
package jsn_net
import (
"fmt"
"os"
"time"
)
type Logger interface {
Debug(string, ...any)
Info(string, ...any)
Warn(string, ...any)
Error(string, ...any)
Fatal(string, ...any)
}
var (
logger Logger
)
func init() {
logger = new(defaultFmtLogger)
}
func SetLogger(in Logger) {
logger = in
}
type defaultFmtLogger struct{}
// Fatal implements Logger.
func (*defaultFmtLogger) Fatal(format string, params ...any) {
fmt.Printf("[%v][Fatal]"+format+"\n", append(append([]any{}, time.Now().Format("2006-01-02 15:04:05.999999")), params...)...)
os.Exit(2)
}
// Warn implements Logger.
func (*defaultFmtLogger) Warn(format string, params ...any) {
fmt.Printf("[%v][Warn]"+format+"\n", append(append([]any{}, time.Now().Format("2006-01-02 15:04:05.999999")), params...)...)
}
func (d defaultFmtLogger) Debug(format string, params ...any) {
fmt.Printf("[%v][Debug]"+format+"\n", append(append([]any{}, time.Now().Format("2006-01-02 15:04:05.999999")), params...)...)
}
func (d defaultFmtLogger) Panic(format string, params ...any) {
panic(fmt.Errorf(format, params...))
}
func (d defaultFmtLogger) Info(format string, params ...any) {
fmt.Printf("[%v][Info]"+format+"\n", append(append([]any{}, time.Now().Format("2006-01-02 15:04:05.999999")), params...)...)
}
func (d defaultFmtLogger) Error(format string, params ...any) {
fmt.Printf("[%v][Error]"+format+"\n", append(append([]any{}, time.Now().Format("2006-01-02 15:04:05.999999")), params...)...)
}