-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprefix.go
96 lines (72 loc) · 2.06 KB
/
prefix.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
86
87
88
89
90
91
92
93
94
95
96
package logger
import (
"fmt"
)
type PrefixLogger struct {
Logger
prefix string
}
var _ Logger = (*PrefixLogger)(nil)
func NewPrefixLogger(origin Logger, prefix string, args ...any)(l *PrefixLogger){
return &PrefixLogger{
prefix: fmt.Sprintf(prefix, args...),
Logger: origin,
}
}
func (l *PrefixLogger)Prefix()(string){
return l.prefix
}
func (l *PrefixLogger)SetPrefix(prefix string, args ...any){
l.prefix = fmt.Sprintf(prefix, args...)
}
func (l *PrefixLogger)Unwrap()(BasicLogger){
return l.Logger
}
func (l *PrefixLogger)Print(v ...any){
l.Logger.Print(addOrInsertPrefix(l.prefix, v)...)
}
func (l *PrefixLogger)Printf(format string, v ...any){
l.Logger.Printf(l.prefix + " " + format, v...)
}
func (l *PrefixLogger)Trace(v ...any){
l.Logger.Trace(addOrInsertPrefix(l.prefix, v)...)
}
func (l *PrefixLogger)Tracef(format string, v ...any){
l.Logger.Tracef(l.prefix + " " + format, v...)
}
func (l *PrefixLogger)Debug(v ...any){
l.Logger.Debug(addOrInsertPrefix(l.prefix, v)...)
}
func (l *PrefixLogger)Debugf(format string, v ...any){
l.Logger.Debugf(l.prefix + " " + format, v...)
}
func (l *PrefixLogger)Info(v ...any){
l.Logger.Info(addOrInsertPrefix(l.prefix, v)...)
}
func (l *PrefixLogger)Infof(format string, v ...any){
l.Logger.Infof(l.prefix + " " + format, v...)
}
func (l *PrefixLogger)Warn(v ...any){
l.Logger.Warn(addOrInsertPrefix(l.prefix, v)...)
}
func (l *PrefixLogger)Warnf(format string, v ...any){
l.Logger.Warnf(l.prefix + " " + format, v...)
}
func (l *PrefixLogger)Error(v ...any){
l.Logger.Error(addOrInsertPrefix(l.prefix, v)...)
}
func (l *PrefixLogger)Errorf(format string, v ...any){
l.Logger.Errorf(l.prefix + " " + format, v...)
}
func (l *PrefixLogger)Fatal(v ...any){
l.Logger.Fatal(addOrInsertPrefix(l.prefix, v)...)
}
func (l *PrefixLogger)Fatalf(format string, v ...any){
l.Logger.Fatalf(l.prefix + " " + format, v...)
}
func (l *PrefixLogger)Panic(v ...any){
l.Logger.Panic(addOrInsertPrefix(l.prefix, v)...)
}
func (l *PrefixLogger)Panicf(format string, v ...any){
l.Logger.Panicf(l.prefix + " " + format, v...)
}