rename InputWriter -> Writer

This commit is contained in:
Patrick Hemmer 2015-01-26 09:59:50 -05:00
parent ed888975b3
commit 51cbf81dde
2 changed files with 31 additions and 31 deletions

View File

@ -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()
}

31
writer.go Normal file
View File

@ -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()
}