diff --git a/input_writer.go b/input_writer.go deleted file mode 100644 index e6db8e7..0000000 --- a/input_writer.go +++ /dev/null @@ -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() -} diff --git a/writer.go b/writer.go new file mode 100644 index 0000000..90d3e01 --- /dev/null +++ b/writer.go @@ -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() +}