diff --git a/fixtures/large_stdout/Procfile b/fixtures/large_stdout/Procfile new file mode 100644 index 0000000..3684bb6 --- /dev/null +++ b/fixtures/large_stdout/Procfile @@ -0,0 +1,2 @@ +stdout1: ruby ./stdout.rb +stdout2: ruby ./stdout.rb diff --git a/fixtures/large_stdout/stdout.rb b/fixtures/large_stdout/stdout.rb new file mode 100644 index 0000000..db2d87a --- /dev/null +++ b/fixtures/large_stdout/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!" diff --git a/outlet.go b/outlet.go index 946c485..4a8eee2 100644 --- a/outlet.go +++ b/outlet.go @@ -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) + } } }