-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtext_logger.go
120 lines (98 loc) · 3.81 KB
/
text_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
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
package log
import (
"context"
"fmt"
)
type logger struct {
logParser
}
// NewLog creates a new Logger instance using existing config from the Logger.
//
// Default configuration values can be overridden by providing Options to the function.
func (l *logger) NewLog(opts ...Option) Logger {
defaults := l.logOptions.copy()
defaults.apply(opts...)
return &logger{
logParser: logParser{
logOptions: defaults,
log: l.log,
},
}
}
// NewPrefixedLog creates a new NewPrefixedLogger instance using existing config from the Logger.
//
// Default configuration values can be overridden by providing Options to the function.
func (l *logger) NewPrefixedLog(opts ...Option) PrefixedLogger {
defaults := l.logOptions.copy()
defaults.apply(opts...)
return &prefixedLogger{
logParser: logParser{
logOptions: defaults,
log: l.log,
},
}
}
// ErrorContext logs with ERROR level with context.
func (l *logger) ErrorContext(ctx context.Context, message interface{}, params ...interface{}) {
l.logEntry(ctx, ERROR, l.WithPrefix(``, message), params...)
}
// WarnContext logs with WARN level with context.
func (l *logger) WarnContext(ctx context.Context, message interface{}, params ...interface{}) {
l.logEntry(ctx, WARN, l.WithPrefix(``, message), params...)
}
// InfoContext logs with INFO level with context.
func (l *logger) InfoContext(ctx context.Context, message interface{}, params ...interface{}) {
l.logEntry(ctx, INFO, l.WithPrefix(``, message), params...)
}
// DebugContext logs with DEBUG level with context.
func (l *logger) DebugContext(ctx context.Context, message interface{}, params ...interface{}) {
l.logEntry(ctx, DEBUG, l.WithPrefix(``, message), params...)
}
// TraceContext logs with TRACE level with context.
func (l *logger) TraceContext(ctx context.Context, message interface{}, params ...interface{}) {
l.logEntry(ctx, TRACE, l.WithPrefix(``, message), params...)
}
// FatalContext logs with FATAL level with context.
func (l *logger) FatalContext(ctx context.Context, message interface{}, params ...interface{}) {
l.logEntry(context.Background(), FATAL, message, params)
}
// Error logs with ERROR level.
func (l *logger) Error(message interface{}, params ...interface{}) {
l.logEntry(context.Background(), ERROR, l.WithPrefix(``, message), params...)
}
// Warn logs with WARN level.
func (l *logger) Warn(message interface{}, params ...interface{}) {
l.logEntry(context.Background(), WARN, l.WithPrefix(``, message), params...)
}
// Info logs with INFO level.
func (l *logger) Info(message interface{}, params ...interface{}) {
l.logEntry(context.Background(), INFO, l.WithPrefix(``, message), params...)
}
// Debug logs with DEBUG level.
func (l *logger) Debug(message interface{}, params ...interface{}) {
l.logEntry(context.Background(), DEBUG, l.WithPrefix(``, message), params...)
}
// Trace logs with TRACE level.
func (l *logger) Trace(message interface{}, params ...interface{}) {
l.logEntry(context.Background(), TRACE, l.WithPrefix(``, message), params...)
}
// Fatal logs with FATAL level.
func (l *logger) Fatal(message interface{}, params ...interface{}) {
l.logEntry(context.Background(), FATAL, l.WithPrefix(``, message), params...)
}
// Fatalln logs with FATAL level.
func (l *logger) Fatalln(message interface{}, params ...interface{}) {
l.logEntry(context.Background(), FATAL, l.WithPrefix(``, message), params...)
}
// Print logs with INFO level.
func (l *logger) Print(v ...interface{}) {
l.logEntry(context.Background(), INFO, l.WithPrefix(``, v), `INFO`)
}
// Printf logs with INFO level.
func (l *logger) Printf(format string, v ...interface{}) {
l.logEntry(context.Background(), INFO, l.WithPrefix(``, fmt.Sprintf(format, v...)), `INFO`)
}
// Println logs with INFO level.
func (l *logger) Println(v ...interface{}) {
l.logEntry(context.Background(), INFO, l.WithPrefix(``, v), `INFO`)
}