summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mattermost/logr/format/plain.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2020-10-19 23:40:00 +0200
committerGitHub <noreply@github.com>2020-10-19 23:40:00 +0200
commit075a84427f6332aab707d283ad770d69f8816032 (patch)
tree0ff9f56a057919f3fe968e57f6f0b1c0d1f85078 /vendor/github.com/mattermost/logr/format/plain.go
parent950f2759bd2b20aa0bdedc3dc9a74d0dafb606d8 (diff)
downloadmatterbridge-msglm-075a84427f6332aab707d283ad770d69f8816032.tar.gz
matterbridge-msglm-075a84427f6332aab707d283ad770d69f8816032.tar.bz2
matterbridge-msglm-075a84427f6332aab707d283ad770d69f8816032.zip
Update vendor (#1265)
Diffstat (limited to 'vendor/github.com/mattermost/logr/format/plain.go')
-rw-r--r--vendor/github.com/mattermost/logr/format/plain.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/vendor/github.com/mattermost/logr/format/plain.go b/vendor/github.com/mattermost/logr/format/plain.go
new file mode 100644
index 00000000..3fa92b49
--- /dev/null
+++ b/vendor/github.com/mattermost/logr/format/plain.go
@@ -0,0 +1,75 @@
+package format
+
+import (
+ "bytes"
+ "fmt"
+
+ "github.com/mattermost/logr"
+)
+
+// Plain is the simplest formatter, outputting only text with
+// no colors.
+type Plain struct {
+ // DisableTimestamp disables output of timestamp field.
+ DisableTimestamp bool
+ // DisableLevel disables output of level field.
+ DisableLevel bool
+ // DisableMsg disables output of msg field.
+ DisableMsg bool
+ // DisableContext disables output of all context fields.
+ DisableContext bool
+ // DisableStacktrace disables output of stack trace.
+ DisableStacktrace bool
+
+ // Delim is an optional delimiter output between each log field.
+ // Defaults to a single space.
+ Delim string
+
+ // TimestampFormat is an optional format for timestamps. If empty
+ // then DefTimestampFormat is used.
+ TimestampFormat string
+}
+
+// Format converts a log record to bytes.
+func (p *Plain) Format(rec *logr.LogRec, stacktrace bool, buf *bytes.Buffer) (*bytes.Buffer, error) {
+ delim := p.Delim
+ if delim == "" {
+ delim = " "
+ }
+ if buf == nil {
+ buf = &bytes.Buffer{}
+ }
+
+ timestampFmt := p.TimestampFormat
+ if timestampFmt == "" {
+ timestampFmt = logr.DefTimestampFormat
+ }
+
+ if !p.DisableTimestamp {
+ var arr [128]byte
+ tbuf := rec.Time().AppendFormat(arr[:0], timestampFmt)
+ buf.Write(tbuf)
+ buf.WriteString(delim)
+ }
+ if !p.DisableLevel {
+ fmt.Fprintf(buf, "%v%s", rec.Level().Name, delim)
+ }
+ if !p.DisableMsg {
+ fmt.Fprint(buf, rec.Msg(), delim)
+ }
+ if !p.DisableContext {
+ ctx := rec.Fields()
+ if len(ctx) > 0 {
+ logr.WriteFields(buf, ctx, " ")
+ }
+ }
+ if stacktrace && !p.DisableStacktrace {
+ frames := rec.StackFrames()
+ if len(frames) > 0 {
+ buf.WriteString("\n")
+ logr.WriteStacktrace(buf, rec.StackFrames())
+ }
+ }
+ buf.WriteString("\n")
+ return buf, nil
+}