diff options
author | Wim <wim@42.be> | 2018-02-20 23:41:09 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2018-02-20 23:41:09 +0100 |
commit | 6ea368c383ccc19678623c51d8e4ecbbdb0a64ac (patch) | |
tree | 0ccce9d453a743c59abf58eb510ccab99128e381 /vendor/github.com/sirupsen/logrus/writer.go | |
parent | e92b6de09fd9d983deea17113b28aaba14863735 (diff) | |
download | matterbridge-msglm-6ea368c383ccc19678623c51d8e4ecbbdb0a64ac.tar.gz matterbridge-msglm-6ea368c383ccc19678623c51d8e4ecbbdb0a64ac.tar.bz2 matterbridge-msglm-6ea368c383ccc19678623c51d8e4ecbbdb0a64ac.zip |
Move Sirupsen => sirupsen
Diffstat (limited to 'vendor/github.com/sirupsen/logrus/writer.go')
-rw-r--r-- | vendor/github.com/sirupsen/logrus/writer.go | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/vendor/github.com/sirupsen/logrus/writer.go b/vendor/github.com/sirupsen/logrus/writer.go new file mode 100644 index 00000000..7bdebedc --- /dev/null +++ b/vendor/github.com/sirupsen/logrus/writer.go @@ -0,0 +1,62 @@ +package logrus + +import ( + "bufio" + "io" + "runtime" +) + +func (logger *Logger) Writer() *io.PipeWriter { + return logger.WriterLevel(InfoLevel) +} + +func (logger *Logger) WriterLevel(level Level) *io.PipeWriter { + return NewEntry(logger).WriterLevel(level) +} + +func (entry *Entry) Writer() *io.PipeWriter { + return entry.WriterLevel(InfoLevel) +} + +func (entry *Entry) WriterLevel(level Level) *io.PipeWriter { + reader, writer := io.Pipe() + + var printFunc func(args ...interface{}) + + switch level { + case DebugLevel: + printFunc = entry.Debug + case InfoLevel: + printFunc = entry.Info + case WarnLevel: + printFunc = entry.Warn + case ErrorLevel: + printFunc = entry.Error + case FatalLevel: + printFunc = entry.Fatal + case PanicLevel: + printFunc = entry.Panic + default: + printFunc = entry.Print + } + + go entry.writerScanner(reader, printFunc) + runtime.SetFinalizer(writer, writerFinalizer) + + return writer +} + +func (entry *Entry) writerScanner(reader *io.PipeReader, printFunc func(args ...interface{})) { + scanner := bufio.NewScanner(reader) + for scanner.Scan() { + printFunc(scanner.Text()) + } + if err := scanner.Err(); err != nil { + entry.Errorf("Error while reading from Writer: %s", err) + } + reader.Close() +} + +func writerFinalizer(writer *io.PipeWriter) { + writer.Close() +} |