mirror of https://github.com/sirupsen/logrus.git
rename InputWriter -> Writer
This commit is contained in:
parent
ed888975b3
commit
51cbf81dde
|
@ -1,31 +0,0 @@
|
|||
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.Errorf("Error while reading from InputWriter: %s", err)
|
||||
}
|
||||
inputReader.Close()
|
||||
}
|
||||
|
||||
func inputWriterFinalizer(inputWriter *io.PipeWriter) {
|
||||
inputWriter.Close()
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package logrus
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func (logger *Logger) Writer() (*io.PipeWriter) {
|
||||
reader, writer := io.Pipe()
|
||||
|
||||
go logger.writerScanner(reader)
|
||||
runtime.SetFinalizer(writer, writerFinalizer)
|
||||
|
||||
return writer
|
||||
}
|
||||
|
||||
func (logger *Logger) writerScanner(reader *io.PipeReader) {
|
||||
scanner := bufio.NewScanner(reader)
|
||||
for scanner.Scan() {
|
||||
logger.Print(scanner.Text())
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
logger.Errorf("Error while reading from Writer: %s", err)
|
||||
}
|
||||
reader.Close()
|
||||
}
|
||||
|
||||
func writerFinalizer(writer *io.PipeWriter) {
|
||||
writer.Close()
|
||||
}
|
Loading…
Reference in New Issue