mirror of
https://github.com/vbatts/go-mtree.git
synced 2024-11-27 02:25:40 +00:00
72ac04e7ca
With: $ git mv vendor/github.com/{S,s}irupsen $ sed -i 's/Sirupsen/sirupsen/g' $(git grep -l Sirupsen) catching up with the upstream lowercasing [1,2,3,4]. Because of the compatibility issues discussed in [3], some consumers may prefer to use the old uppercase version until they have time to update their other Logrus consumers to the new lowercase form. [1]: https://github.com/sirupsen/logrus/blame/v1.0.3/README.md#L6 [2]: https://github.com/sirupsen/logrus/pull/384 [3]: https://github.com/sirupsen/logrus/issues/570#issuecomment-313933276 [4]: https://github.com/sirupsen/logrus/issues/553
62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
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()
|
|
}
|