1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-18 08:26:45 +02:00
woodpecker/vendor/github.com/Sirupsen/logrus/writer.go

32 lines
570 B
Go
Raw Normal View History

2015-05-22 20:37:40 +02:00
package logrus
import (
"bufio"
"io"
"runtime"
)
2016-04-12 00:55:13 +02:00
func (logger *Logger) Writer() *io.PipeWriter {
2015-05-22 20:37:40 +02:00
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()
}