-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfacade.go
More file actions
57 lines (47 loc) · 1.9 KB
/
Copy pathfacade.go
File metadata and controls
57 lines (47 loc) · 1.9 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
package zerologr
import "github.com/go-logr/logr"
//nolint:gochecknoglobals
var logger = New(&Opts{})
// Set replaces the global logger with a new one.
func Set(newLogger logr.Logger) {
// Set replaces the global logger with a new one.
// We need to adjust the call depth because the logger is called from this package, meaning an
// extra frame is added to the stack trace.
logger = newLogger.WithCallDepth(1)
}
// Enabled returns true if the global logger is enabled for the current verbosity level.
func Enabled() bool {
return logger.Enabled()
}
// V returns the global logger with the specified verbosity level.
func V(level int) logr.Logger {
// Have to remove one frame of call depth because the stack depth is reduced from using the
// returned logger.
return logger.V(level).WithCallDepth(-1)
}
// Info logs an info message with the global logger.
func Info(msg string, keysAndValues ...any) {
logger.Info(msg, keysAndValues...)
}
// Error logs an error message with the global logger.
func Error(err error, msg string, keysAndValues ...any) {
logger.Error(err, msg, keysAndValues...)
}
// WithName returns a new logger with the specified name, using the global logger as a base.
func WithName(name string) logr.Logger {
// Have to remove one frame of call depth because the stack depth is reduced from using the
// returned logger.
return logger.WithName(name).WithCallDepth(-1)
}
// WithValues returns a new logger with the specified key-value pairs, using the global logger as
// a base.
func WithValues(keysAndValues ...any) logr.Logger {
// Have to remove one frame of call depth because the stack depth is reduced from using the
// returned logger.
return logger.WithValues(keysAndValues...).WithCallDepth(-1)
}
// WithCallDepth returns a new logger with the specified call depth, using the global logger as a
// base.
func WithCallDepth(depth int) logr.Logger {
return logger.WithCallDepth(depth)
}