2015-01-08 09:04:07 +03:00
|
|
|
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 {
|
2015-01-20 18:11:57 +03:00
|
|
|
logger.Errorf("Error while reading from InputWriter: %s", err)
|
2015-01-08 09:04:07 +03:00
|
|
|
}
|
2015-01-20 18:11:57 +03:00
|
|
|
inputReader.Close()
|
2015-01-08 09:04:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func inputWriterFinalizer(inputWriter *io.PipeWriter) {
|
|
|
|
inputWriter.Close()
|
|
|
|
}
|