summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mattermost/logr/v2/sugar.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2021-12-12 00:05:15 +0100
committerGitHub <noreply@github.com>2021-12-12 00:05:15 +0100
commit3893a035be347a7687a41d2054dd1b274d3a0504 (patch)
treedfe4a3bf72a0a6356e51bd8fc2e88e9a26e52331 /vendor/github.com/mattermost/logr/v2/sugar.go
parent658bdd9faa835660ae407331732e9d93d8f6443b (diff)
downloadmatterbridge-msglm-3893a035be347a7687a41d2054dd1b274d3a0504.tar.gz
matterbridge-msglm-3893a035be347a7687a41d2054dd1b274d3a0504.tar.bz2
matterbridge-msglm-3893a035be347a7687a41d2054dd1b274d3a0504.zip
Update dependencies/vendor (#1659)
Diffstat (limited to 'vendor/github.com/mattermost/logr/v2/sugar.go')
-rw-r--r--vendor/github.com/mattermost/logr/v2/sugar.go78
1 files changed, 78 insertions, 0 deletions
diff --git a/vendor/github.com/mattermost/logr/v2/sugar.go b/vendor/github.com/mattermost/logr/v2/sugar.go
index f4f300ee..882f0fd5 100644
--- a/vendor/github.com/mattermost/logr/v2/sugar.go
+++ b/vendor/github.com/mattermost/logr/v2/sugar.go
@@ -117,3 +117,81 @@ func (s Sugar) Fatalf(format string, args ...interface{}) {
func (s Sugar) Panicf(format string, args ...interface{}) {
s.Logf(Panic, format, args...)
}
+
+//
+// K/V style
+//
+
+// With returns a new Sugar logger with the specified key/value pairs added to the
+// fields list.
+func (s Sugar) With(keyValuePairs ...interface{}) Sugar {
+ return s.logger.With(s.argsToFields(keyValuePairs)...).Sugar()
+}
+
+// Tracew outputs at trace level with the specified key/value pairs converted to fields.
+func (s Sugar) Tracew(msg string, keyValuePairs ...interface{}) {
+ s.logger.Log(Trace, msg, s.argsToFields(keyValuePairs)...)
+}
+
+// Debugw outputs at debug level with the specified key/value pairs converted to fields.
+func (s Sugar) Debugw(msg string, keyValuePairs ...interface{}) {
+ s.logger.Log(Debug, msg, s.argsToFields(keyValuePairs)...)
+}
+
+// Infow outputs at info level with the specified key/value pairs converted to fields.
+func (s Sugar) Infow(msg string, keyValuePairs ...interface{}) {
+ s.logger.Log(Info, msg, s.argsToFields(keyValuePairs)...)
+}
+
+// Warnw outputs at warn level with the specified key/value pairs converted to fields.
+func (s Sugar) Warnw(msg string, keyValuePairs ...interface{}) {
+ s.logger.Log(Warn, msg, s.argsToFields(keyValuePairs)...)
+}
+
+// Errorw outputs at error level with the specified key/value pairs converted to fields.
+func (s Sugar) Errorw(msg string, keyValuePairs ...interface{}) {
+ s.logger.Log(Error, msg, s.argsToFields(keyValuePairs)...)
+}
+
+// Fatalw outputs at fatal level with the specified key/value pairs converted to fields.
+func (s Sugar) Fatalw(msg string, keyValuePairs ...interface{}) {
+ s.logger.Log(Fatal, msg, s.argsToFields(keyValuePairs)...)
+}
+
+// Panicw outputs at panic level with the specified key/value pairs converted to fields.
+func (s Sugar) Panicw(msg string, keyValuePairs ...interface{}) {
+ s.logger.Log(Panic, msg, s.argsToFields(keyValuePairs)...)
+}
+
+// argsToFields converts an array of args, possibly containing name/value pairs
+// into a []Field.
+func (s Sugar) argsToFields(keyValuePairs []interface{}) []Field {
+ if len(keyValuePairs) == 0 {
+ return nil
+ }
+
+ fields := make([]Field, 0, len(keyValuePairs))
+ count := len(keyValuePairs)
+
+ for i := 0; i < count; {
+ if fld, ok := keyValuePairs[i].(Field); ok {
+ fields = append(fields, fld)
+ i++
+ continue
+ }
+
+ if i == count-1 {
+ s.logger.Error("invalid key/value pair", Any("arg", keyValuePairs[i]))
+ break
+ }
+
+ // we should have a key/value pair now. The key must be a string.
+ if key, ok := keyValuePairs[i].(string); !ok {
+ s.logger.Error("invalid key for key/value pair", Int("pos", i))
+ } else {
+ fields = append(fields, Any(key, keyValuePairs[i+1]))
+ }
+ i += 2
+ }
+ return fields
+}