This repository has been archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger_format.go
85 lines (69 loc) · 2.6 KB
/
logger_format.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package rec
import (
"fmt"
"time"
)
type formatLogger struct {
l *Logger
}
// F returns format logger utilities.
func (l *Logger) F() *formatLogger { // nolint: revive
return &formatLogger{
l: l,
}
}
// F returns default `*rec.Logger` in rec package as `*rec.formatLogger`.
func F() *formatLogger { // nolint: revive
return defaultLogger.F()
}
// Print outputs the log entry for the passed rec.Severity.
func (f *formatLogger) Printf(severity Severity, format string, v ...interface{}) {
f.l.write(time.Now(), severity, fmt.Sprintf(format, v...))
}
// Fatal outputs the log entry for the passed rec.Severity and call os.Exit(1).
func (f *formatLogger) Fatalf(severity Severity, format string, v ...interface{}) {
f.l.write(time.Now(), severity, fmt.Sprintf(format, v...))
exitFn(1)
}
// Panic outputs the log entry for the passed rec.Severity and call panic(message).
func (f *formatLogger) Panicf(severity Severity, format string, v ...interface{}) {
message := fmt.Sprintf(format, v...)
f.l.write(time.Now(), severity, message)
panic(message)
}
// Default outputs the DEFAULT Severity log entry.
func (f *formatLogger) Defaultf(format string, v ...interface{}) {
f.l.write(time.Now(), DEFAULT, fmt.Sprintf(format, v...))
}
// Debug outputs the DEBUG Severity log entry.
func (f *formatLogger) Debugf(format string, v ...interface{}) {
f.l.write(time.Now(), DEBUG, fmt.Sprintf(format, v...))
}
// Info outputs the INFO Severity log entry.
func (f *formatLogger) Infof(format string, v ...interface{}) {
f.l.write(time.Now(), INFO, fmt.Sprintf(format, v...))
}
// Notice outputs the NOTICE Severity log entry.
func (f *formatLogger) Noticef(format string, v ...interface{}) {
f.l.write(time.Now(), NOTICE, fmt.Sprintf(format, v...))
}
// Warning outputs the WARNING Severity log entry.
func (f *formatLogger) Warningf(format string, v ...interface{}) {
f.l.write(time.Now(), WARNING, fmt.Sprintf(format, v...))
}
// Error outputs the ERROR Severity log entry.
func (f *formatLogger) Errorf(format string, v ...interface{}) {
f.l.write(time.Now(), ERROR, fmt.Sprintf(format, v...))
}
// Critical outputs the CRITICAL Severity log entry.
func (f *formatLogger) Criticalf(format string, v ...interface{}) {
f.l.write(time.Now(), CRITICAL, fmt.Sprintf(format, v...))
}
// Alert outputs the ALERT Severity log entry.
func (f *formatLogger) Alertf(format string, v ...interface{}) {
f.l.write(time.Now(), ALERT, fmt.Sprintf(format, v...))
}
// Emergency outputs the EMERGENCY Severity log entry.
func (f *formatLogger) Emergencyf(format string, v ...interface{}) {
f.l.write(time.Now(), EMERGENCY, fmt.Sprintf(format, v...))
}