mirror of
https://github.com/thegeeklab/drone-s3-sync.git
synced 2024-11-26 16:50:35 +00:00
32 lines
570 B
Go
32 lines
570 B
Go
|
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()
|
||
|
}
|