diff options
author | Wim <wim@42.be> | 2020-10-19 23:40:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-19 23:40:00 +0200 |
commit | 075a84427f6332aab707d283ad770d69f8816032 (patch) | |
tree | 0ff9f56a057919f3fe968e57f6f0b1c0d1f85078 /vendor/github.com/mattermost/logr/target/writer.go | |
parent | 950f2759bd2b20aa0bdedc3dc9a74d0dafb606d8 (diff) | |
download | matterbridge-msglm-075a84427f6332aab707d283ad770d69f8816032.tar.gz matterbridge-msglm-075a84427f6332aab707d283ad770d69f8816032.tar.bz2 matterbridge-msglm-075a84427f6332aab707d283ad770d69f8816032.zip |
Update vendor (#1265)
Diffstat (limited to 'vendor/github.com/mattermost/logr/target/writer.go')
-rw-r--r-- | vendor/github.com/mattermost/logr/target/writer.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/vendor/github.com/mattermost/logr/target/writer.go b/vendor/github.com/mattermost/logr/target/writer.go new file mode 100644 index 00000000..2250da51 --- /dev/null +++ b/vendor/github.com/mattermost/logr/target/writer.go @@ -0,0 +1,40 @@ +package target + +import ( + "io" + "io/ioutil" + + "github.com/mattermost/logr" +) + +// Writer outputs log records to any `io.Writer`. +type Writer struct { + logr.Basic + out io.Writer +} + +// NewWriterTarget creates a target capable of outputting log records to an io.Writer. +func NewWriterTarget(filter logr.Filter, formatter logr.Formatter, out io.Writer, maxQueue int) *Writer { + if out == nil { + out = ioutil.Discard + } + w := &Writer{out: out} + w.Basic.Start(w, w, filter, formatter, maxQueue) + return w +} + +// Write converts the log record to bytes, via the Formatter, +// and outputs to the io.Writer. +func (w *Writer) Write(rec *logr.LogRec) error { + _, stacktrace := w.IsLevelEnabled(rec.Level()) + + buf := rec.Logger().Logr().BorrowBuffer() + defer rec.Logger().Logr().ReleaseBuffer(buf) + + buf, err := w.Formatter().Format(rec, stacktrace, buf) + if err != nil { + return err + } + _, err = w.out.Write(buf.Bytes()) + return err +} |