mirror of https://github.com/sirupsen/logrus.git
31 lines
586 B
Go
31 lines
586 B
Go
|
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()
|
||
|
}
|