mirror of https://github.com/sirupsen/logrus.git
add io.Writer interface compatability
This commit is contained in:
parent
d2f9ffa1d9
commit
299ee95277
|
@ -9,6 +9,10 @@ var (
|
||||||
std = New()
|
std = New()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func StandardLogger() *Logger {
|
||||||
|
return std
|
||||||
|
}
|
||||||
|
|
||||||
// SetOutput sets the standard logger output.
|
// SetOutput sets the standard logger output.
|
||||||
func SetOutput(out io.Writer) {
|
func SetOutput(out io.Writer) {
|
||||||
std.mu.Lock()
|
std.mu.Lock()
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package logrus
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"io"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (logger *Logger) InputWriter() (*io.PipeWriter) {
|
||||||
|
inputReader, inputWriter := io.Pipe()
|
||||||
|
|
||||||
|
go logger.inputWriterScanner(inputReader)
|
||||||
|
runtime.SetFinalizer(inputWriter, inputWriterFinalizer)
|
||||||
|
|
||||||
|
return inputWriter
|
||||||
|
}
|
||||||
|
|
||||||
|
func (logger *Logger) inputWriterScanner(inputReader *io.PipeReader) {
|
||||||
|
scanner := bufio.NewScanner(inputReader)
|
||||||
|
for scanner.Scan() {
|
||||||
|
logger.Print(scanner.Text())
|
||||||
|
}
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
logger.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func inputWriterFinalizer(inputWriter *io.PipeWriter) {
|
||||||
|
inputWriter.Close()
|
||||||
|
}
|
Loading…
Reference in New Issue