summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mattermost/logr/v2/sugar.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2021-10-16 23:11:32 +0200
committerWim <wim@42.be>2021-10-16 23:23:24 +0200
commit20f6c05ec50739d31f4dbe9fde0d223f2c43f6e8 (patch)
tree230edca06449a8d1755f08aabf45a03e07e6f17c /vendor/github.com/mattermost/logr/v2/sugar.go
parent57fce93af7f64f025cec6f3ed6088163086bc9fe (diff)
downloadmatterbridge-msglm-20f6c05ec50739d31f4dbe9fde0d223f2c43f6e8.tar.gz
matterbridge-msglm-20f6c05ec50739d31f4dbe9fde0d223f2c43f6e8.tar.bz2
matterbridge-msglm-20f6c05ec50739d31f4dbe9fde0d223f2c43f6e8.zip
Update vendor
Diffstat (limited to 'vendor/github.com/mattermost/logr/v2/sugar.go')
-rw-r--r--vendor/github.com/mattermost/logr/v2/sugar.go119
1 files changed, 119 insertions, 0 deletions
diff --git a/vendor/github.com/mattermost/logr/v2/sugar.go b/vendor/github.com/mattermost/logr/v2/sugar.go
new file mode 100644
index 00000000..f4f300ee
--- /dev/null
+++ b/vendor/github.com/mattermost/logr/v2/sugar.go
@@ -0,0 +1,119 @@
+package logr
+
+import (
+ "fmt"
+)
+
+// Sugar provides a less structured API for logging.
+type Sugar struct {
+ logger Logger
+}
+
+func (s Sugar) sugarLog(lvl Level, msg string, args ...interface{}) {
+ if s.logger.IsLevelEnabled(lvl) {
+ fields := make([]Field, 0, len(args))
+ for _, arg := range args {
+ fields = append(fields, Any("", arg))
+ }
+ s.logger.Log(lvl, msg, fields...)
+ }
+}
+
+// Trace is a convenience method equivalent to `Log(TraceLevel, msg, args...)`.
+func (s Sugar) Trace(msg string, args ...interface{}) {
+ s.sugarLog(Trace, msg, args...)
+}
+
+// Debug is a convenience method equivalent to `Log(DebugLevel, msg, args...)`.
+func (s Sugar) Debug(msg string, args ...interface{}) {
+ s.sugarLog(Debug, msg, args...)
+}
+
+// Print ensures compatibility with std lib logger.
+func (s Sugar) Print(msg string, args ...interface{}) {
+ s.Info(msg, args...)
+}
+
+// Info is a convenience method equivalent to `Log(InfoLevel, msg, args...)`.
+func (s Sugar) Info(msg string, args ...interface{}) {
+ s.sugarLog(Info, msg, args...)
+}
+
+// Warn is a convenience method equivalent to `Log(WarnLevel, msg, args...)`.
+func (s Sugar) Warn(msg string, args ...interface{}) {
+ s.sugarLog(Warn, msg, args...)
+}
+
+// Error is a convenience method equivalent to `Log(ErrorLevel, msg, args...)`.
+func (s Sugar) Error(msg string, args ...interface{}) {
+ s.sugarLog(Error, msg, args...)
+}
+
+// Fatal is a convenience method equivalent to `Log(FatalLevel, msg, args...)`
+func (s Sugar) Fatal(msg string, args ...interface{}) {
+ s.sugarLog(Fatal, msg, args...)
+}
+
+// Panic is a convenience method equivalent to `Log(PanicLevel, msg, args...)`
+func (s Sugar) Panic(msg string, args ...interface{}) {
+ s.sugarLog(Panic, msg, args...)
+}
+
+//
+// Printf style
+//
+
+// Logf checks that the level matches one or more targets, and
+// if so, generates a log record that is added to the main
+// queue (channel). Arguments are handled in the manner of fmt.Printf.
+func (s Sugar) Logf(lvl Level, format string, args ...interface{}) {
+ if s.logger.IsLevelEnabled(lvl) {
+ var msg string
+ if format == "" {
+ msg = fmt.Sprint(args...)
+ } else {
+ msg = fmt.Sprintf(format, args...)
+ }
+ s.logger.Log(lvl, msg)
+ }
+}
+
+// Tracef is a convenience method equivalent to `Logf(TraceLevel, args...)`.
+func (s Sugar) Tracef(format string, args ...interface{}) {
+ s.Logf(Trace, format, args...)
+}
+
+// Debugf is a convenience method equivalent to `Logf(DebugLevel, args...)`.
+func (s Sugar) Debugf(format string, args ...interface{}) {
+ s.Logf(Debug, format, args...)
+}
+
+// Infof is a convenience method equivalent to `Logf(InfoLevel, args...)`.
+func (s Sugar) Infof(format string, args ...interface{}) {
+ s.Logf(Info, format, args...)
+}
+
+// Printf ensures compatibility with std lib logger.
+func (s Sugar) Printf(format string, args ...interface{}) {
+ s.Infof(format, args...)
+}
+
+// Warnf is a convenience method equivalent to `Logf(WarnLevel, args...)`.
+func (s Sugar) Warnf(format string, args ...interface{}) {
+ s.Logf(Warn, format, args...)
+}
+
+// Errorf is a convenience method equivalent to `Logf(ErrorLevel, args...)`.
+func (s Sugar) Errorf(format string, args ...interface{}) {
+ s.Logf(Error, format, args...)
+}
+
+// Fatalf is a convenience method equivalent to `Logf(FatalLevel, args...)`
+func (s Sugar) Fatalf(format string, args ...interface{}) {
+ s.Logf(Fatal, format, args...)
+}
+
+// Panicf is a convenience method equivalent to `Logf(PanicLevel, args...)`
+func (s Sugar) Panicf(format string, args ...interface{}) {
+ s.Logf(Panic, format, args...)
+}