mirror of
https://github.com/wahyd4/forego.git
synced 2026-08-09 05:07:05 +10:00
Merge pull request #33 from subicura/master
fix long stdout line read issue
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
stdout1: ruby ./stdout.rb
|
||||
stdout2: ruby ./stdout.rb
|
||||
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
$stdout.sync = true
|
||||
|
||||
10.times do |i|
|
||||
puts "sample log message... " * rand(i*1000) + "ok - #{i}"
|
||||
sleep 1
|
||||
end
|
||||
|
||||
puts "finish!"
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"sync"
|
||||
"bytes"
|
||||
)
|
||||
|
||||
type OutletFactory struct {
|
||||
@@ -33,9 +34,26 @@ func (of *OutletFactory) LineReader(wg *sync.WaitGroup, name string, index int,
|
||||
|
||||
color := colors[index%len(colors)]
|
||||
|
||||
scanner := bufio.NewScanner(r)
|
||||
for scanner.Scan() {
|
||||
of.WriteLine(name, scanner.Text(), color, ct.None, isError)
|
||||
reader := bufio.NewReader(r)
|
||||
|
||||
var buffer bytes.Buffer
|
||||
|
||||
for {
|
||||
buf := make([]byte, 1024)
|
||||
v, _ := reader.Read(buf)
|
||||
|
||||
if v == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
idx := bytes.IndexByte(buf, '\n')
|
||||
if idx >= 0 {
|
||||
buffer.Write(buf[0:idx])
|
||||
of.WriteLine(name, buffer.String(), color, ct.None, isError)
|
||||
buffer.Reset()
|
||||
} else {
|
||||
buffer.Write(buf)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user