-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.go
More file actions
178 lines (144 loc) · 5.77 KB
/
helper.go
File metadata and controls
178 lines (144 loc) · 5.77 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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package mo
import (
"context"
"os"
)
// Helper is a helper struct for logging.
type Helper struct {
Logger *Logger
ctx context.Context
}
// New returns a new Helper with the given context and logger.
func New(ctx context.Context, logger *Logger) *Helper {
return &Helper{ctx: ctx, Logger: logger}
}
// With returns a new Helper with the given context.
func (h Helper) With(ctx context.Context) *Helper {
return &Helper{ctx: ctx, Logger: h.Logger}
}
// Debug logs a message at the debug level.
func (h Helper) Debug(a ...interface{}) {
h.Logger.Print(h.ctx, LevelDebug, a...)
}
// Debugf logs a formatted message at the debug level.
func (h Helper) Debugf(format string, a ...interface{}) {
h.Logger.Printf(h.ctx, LevelDebug, format, a...)
}
// Debugw logs a message with key-value pairs at the debug level.
func (h Helper) Debugw(msg string, kv ...Field) {
h.Logger.Printw(h.ctx, LevelDebug, msg, kv...)
}
// Debugx logs a message at the debug level with the given context.
func (h Helper) Debugx(ctx context.Context, a ...interface{}) {
h.Logger.Print(ctx, LevelDebug, a...)
}
// Debugfx logs a formatted message at the debug level with the given context.
func (h Helper) Debugfx(ctx context.Context, format string, a ...interface{}) {
h.Logger.Printf(ctx, LevelDebug, format, a...)
}
// Debugwx logs a message with key-value pairs at the debug level with the given context.
func (h Helper) Debugwx(ctx context.Context, msg string, kv ...Field) {
h.Logger.Printw(ctx, LevelDebug, msg, kv...)
}
// Info logs a message at the info level.
func (h Helper) Info(a ...interface{}) {
h.Logger.Print(h.ctx, LevelInfo, a...)
}
// Infof logs a formatted message at the info level.
func (h Helper) Infof(format string, a ...interface{}) {
h.Logger.Printf(h.ctx, LevelInfo, format, a...)
}
// Infow logs a message with key-value pairs at the info level.
func (h Helper) Infow(msg string, kv ...Field) {
h.Logger.Printw(h.ctx, LevelInfo, msg, kv...)
}
// Infox logs a message at the info level with the given context.
func (h Helper) Infox(ctx context.Context, a ...interface{}) {
h.Logger.Print(ctx, LevelInfo, a...)
}
// Infofx logs a formatted message at the info level with the given context.
func (h Helper) Infofx(ctx context.Context, format string, a ...interface{}) {
h.Logger.Printf(ctx, LevelInfo, format, a...)
}
// Infowx logs a message with key-value pairs at the info level with the given context.
func (h Helper) Infowx(ctx context.Context, msg string, kv ...Field) {
h.Logger.Printw(ctx, LevelInfo, msg, kv...)
}
// Warn logs a message at the warn level.
func (h Helper) Warn(a ...interface{}) {
h.Logger.Print(h.ctx, LevelWarn, a...)
}
// Warnf logs a formatted message at the warn level.
func (h Helper) Warnf(format string, a ...interface{}) {
h.Logger.Printf(h.ctx, LevelWarn, format, a...)
}
// Warnw logs a message with key-value pairs at the warn level.
func (h Helper) Warnw(msg string, kv ...Field) {
h.Logger.Printw(h.ctx, LevelWarn, msg, kv...)
}
// Warnx logs a message at the warn level with the given context.
func (h Helper) Warnx(ctx context.Context, a ...interface{}) {
h.Logger.Print(ctx, LevelWarn, a...)
}
// Warnfx logs a formatted message at the warn level with the given context.
func (h Helper) Warnfx(ctx context.Context, format string, a ...interface{}) {
h.Logger.Printf(ctx, LevelWarn, format, a...)
}
// Warnwx logs a message with key-value pairs at the warn level with the given context.
func (h Helper) Warnwx(ctx context.Context, msg string, kv ...Field) {
h.Logger.Printw(ctx, LevelWarn, msg, kv...)
}
// Error logs a message at the error level.
func (h Helper) Error(a ...interface{}) {
h.Logger.Print(h.ctx, LevelError, a...)
}
// Errorf logs a formatted message at the error level.
func (h Helper) Errorf(format string, a ...interface{}) {
h.Logger.Printf(h.ctx, LevelError, format, a...)
}
// Errorw logs a message with key-value pairs at the error level.
func (h Helper) Errorw(msg string, kv ...Field) {
h.Logger.Printw(h.ctx, LevelError, msg, kv...)
}
// Errorx logs a message at the error level with the given context.
func (h Helper) Errorx(ctx context.Context, a ...interface{}) {
h.Logger.Print(ctx, LevelError, a...)
}
// Errorfx logs a formatted message at the error level with the given context.
func (h Helper) Errorfx(ctx context.Context, format string, a ...interface{}) {
h.Logger.Printf(ctx, LevelError, format, a...)
}
// Errorwx logs a message with key-value pairs at the error level with the given context.
func (h Helper) Errorwx(ctx context.Context, msg string, kv ...Field) {
h.Logger.Printw(ctx, LevelError, msg, kv...)
}
// Fatal logs a message at the fatal level and exits the program.
func (h Helper) Fatal(a ...interface{}) {
h.Logger.Print(h.ctx, LevelFatal, a...)
os.Exit(1)
}
// Fatalf logs a formatted message at the fatal level and exits the program.
func (h Helper) Fatalf(format string, a ...interface{}) {
h.Logger.Printf(h.ctx, LevelFatal, format, a...)
os.Exit(1)
}
// Fatalw logs a message with key-value pairs at the fatal level and exits the program.
func (h Helper) Fatalw(msg string, kv ...Field) {
h.Logger.Printw(h.ctx, LevelFatal, msg, kv...)
os.Exit(1)
}
// Fatalx logs a message at the fatal level with the given context and exits the program.
func (h Helper) Fatalx(ctx context.Context, a ...interface{}) {
h.Logger.Print(ctx, LevelFatal, a...)
os.Exit(1)
}
// Fatalfx logs a formatted message at the fatal level with the given context and exits the program.
func (h Helper) Fatalfx(ctx context.Context, format string, a ...interface{}) {
h.Logger.Printf(ctx, LevelFatal, format, a...)
os.Exit(1)
}
// Fatalwx logs a message with key-value pairs at the fatal level with the given context and exits the program.
func (h Helper) Fatalwx(ctx context.Context, msg string, kv ...Field) {
h.Logger.Printw(ctx, LevelFatal, msg, kv...)
os.Exit(1)
}