forked from Elara6331/logger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnop.go
155 lines (115 loc) · 4.99 KB
/
nop.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
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
package logger
import (
"fmt"
)
var _ Logger = (*NopLogger)(nil)
// NopLogger implements the Logger interface
// using human-readable output for log messages.
type NopLogger struct{}
// NewNop creates and returns a new NopLogger
func NewNop() NopLogger {
return NopLogger{}
}
// NoPanic prevents the logger from panicking on panic events
func (nl NopLogger) NoPanic() {}
// NoExit prevents the logger from exiting on fatal events
func (nl NopLogger) NoExit() {}
// SetLevel sets the log level of the logger
func (nl NopLogger) SetLevel(LogLevel) {}
// Debug creates a new debug event with the given message
func (nl NopLogger) Debug(msg string) LogBuilder {
return NopLogBuilder{}
}
// Debugf creates a new debug event with the formatted message
func (nl NopLogger) Debugf(format string, v ...any) LogBuilder {
return NopLogBuilder{}
}
// Info creates a new info event with the given message
func (nl NopLogger) Info(msg string) LogBuilder {
return NopLogBuilder{}
}
// Infof creates a new info event with the formatted message
func (nl NopLogger) Infof(format string, v ...any) LogBuilder {
return NopLogBuilder{}
}
// Warn creates a new warn event with the given message
func (nl NopLogger) Warn(msg string) LogBuilder {
return NopLogBuilder{}
}
// Warnf creates a new warn event with the formatted message
func (nl NopLogger) Warnf(format string, v ...any) LogBuilder {
return NopLogBuilder{}
}
// Error creates a new error event with the given message
func (nl NopLogger) Error(msg string) LogBuilder {
return NopLogBuilder{}
}
// Errorf creates a new error event with the formatted message
func (nl NopLogger) Errorf(format string, v ...any) LogBuilder {
return NopLogBuilder{}
}
// Fatal creates a new fatal event with the given message
func (nl NopLogger) Fatal(msg string) LogBuilder {
return NopLogBuilder{}
}
// Fatalf creates a new fatal event with the formatted message
func (nl NopLogger) Fatalf(format string, v ...any) LogBuilder {
return NopLogBuilder{}
}
// Panic creates a new panic event with the given message
func (nl NopLogger) Panic(msg string) LogBuilder {
return NopLogBuilder{}
}
// Panicf creates a new panic event with the formatted message
func (nl NopLogger) Panicf(format string, v ...any) LogBuilder {
return NopLogBuilder{}
}
// NopLogBuilder implements the LogBuilder interface
// using human-readable output for log messages
type NopLogBuilder struct{}
// Int adds an int field to the output
func (nlb NopLogBuilder) Int(key string, val int) LogBuilder { return nlb }
// Int64 adds an int64 field to the output
func (nlb NopLogBuilder) Int64(key string, val int64) LogBuilder { return nlb }
// Int32 adds an int32 field to the output
func (nlb NopLogBuilder) Int32(key string, val int32) LogBuilder { return nlb }
// Int16 adds an int16 field to the output
func (nlb NopLogBuilder) Int16(key string, val int16) LogBuilder { return nlb }
// Int8 adds an int8 field to the output
func (nlb NopLogBuilder) Int8(key string, val int8) LogBuilder { return nlb }
// Uint adds a uint field to the output
func (nlb NopLogBuilder) Uint(key string, val uint) LogBuilder { return nlb }
// Uint64 adds a uint64 field to the output
func (nlb NopLogBuilder) Uint64(key string, val uint64) LogBuilder { return nlb }
// Uint32 adds a uint32 field to the output
func (nlb NopLogBuilder) Uint32(key string, val uint32) LogBuilder { return nlb }
// Uint16 adds a uint16 field to the output
func (nlb NopLogBuilder) Uint16(key string, val uint16) LogBuilder { return nlb }
// Uint8 adds a uint8 field to the output
func (nlb NopLogBuilder) Uint8(key string, val uint8) LogBuilder { return nlb }
// Float64 adds a float64 field to the output
func (nlb NopLogBuilder) Float64(key string, val float64) LogBuilder { return nlb }
// Float32 adds a float32 field to the output
func (nlb NopLogBuilder) Float32(key string, val float32) LogBuilder { return nlb }
// Stringer calls the String method of an fmt.Stringer
// and adds the resulting string as a field to the output
func (nlb NopLogBuilder) Stringer(key string, s fmt.Stringer) LogBuilder { return nlb }
// Bytes writes hex-encoded bytes as a field to the output
func (nlb NopLogBuilder) Bytes(key string, b []byte) LogBuilder { return nlb }
// Timestamp adds the time formatted as RFC3339Nano
// as a field to the output
func (nlb NopLogBuilder) Timestamp() LogBuilder { return nlb }
// Bool adds a bool as a field to the output
func (nlb NopLogBuilder) Bool(key string, val bool) LogBuilder { return nlb }
// Str adds a string as a field to the output
func (nlb NopLogBuilder) Str(key, val string) LogBuilder { return nlb }
// Any uses reflection to marshal any type and writes
// the result as a field to the output. This is much slower
// than the type-specific functions.
func (nlb NopLogBuilder) Any(key string, val any) LogBuilder { return nlb }
// Err adds an error as a field to the output
func (nlb NopLogBuilder) Err(err error) LogBuilder { return nlb }
// Send sends the event to the output.
//
// After calling send, do not use the event again.
func (nlb NopLogBuilder) Send() {}