@@ -11,7 +11,6 @@ import (
1111 "time"
1212
1313 "github.com/fsouza/go-dockerclient"
14- "github.com/hashicorp/go-version"
1514)
1615
1716var allowTTY bool
@@ -181,10 +180,6 @@ func (p *LogsPump) Run() error {
181180
182181func (p * LogsPump ) pumpLogs (event * docker.APIEvents , backlog bool , inactivityTimeout time.Duration ) {
183182 id := normalID (event .ID )
184-
185- dockerVersion , err := p .client .Version ()
186- assert (err , "Could not get Docker Version endpoint" )
187-
188183 container , err := p .client .InspectContainer (id )
189184 assert (err , "pump" )
190185 if ignoreContainerTTY (container ) {
@@ -214,9 +209,16 @@ func (p *LogsPump) pumpLogs(event *docker.APIEvents, backlog bool, inactivityTim
214209 debug ("pump.pumpLogs():" , id , "pump exists" )
215210 return
216211 }
212+
213+ // RawTerminal with container Tty=false injects binary headers into
214+ // the log stream that show up as garbage unicode characters
215+ rawTerminal := false
216+ if allowTTY && container .Config .Tty {
217+ rawTerminal = true
218+ }
217219 outrd , outwr := io .Pipe ()
218220 errrd , errwr := io .Pipe ()
219- p .pumps [id ] = newContainerPump (container , dockerVersion , outrd , errrd )
221+ p .pumps [id ] = newContainerPump (container , outrd , errrd )
220222 p .mu .Unlock ()
221223 p .update (event )
222224 go func () {
@@ -232,7 +234,7 @@ func (p *LogsPump) pumpLogs(event *docker.APIEvents, backlog bool, inactivityTim
232234 Tail : tail ,
233235 Since : sinceTime .Unix (),
234236 InactivityTimeout : inactivityTimeout ,
235- RawTerminal : allowTTY ,
237+ RawTerminal : rawTerminal ,
236238 })
237239 if err != nil {
238240 debug ("pump.pumpLogs():" , id , "stopped with error:" , err )
@@ -344,32 +346,14 @@ type containerPump struct {
344346 logstreams map [chan * Message ]* Route
345347}
346348
347- func newContainerPump (container * docker.Container , dockerVersion * docker.Env , stdout , stderr io.Reader ) * containerPump {
348- apiVersion := dockerVersion .Get ("ApiVersion" )
349- debug ("API Version: " , apiVersion )
350- debug ("TTY is: " , container .Config .Tty )
351- earliestAPI , _ := version .NewVersion ("1.13" )
352- currentAPI , err := version .NewVersion (apiVersion )
353- assert (err , "current docker api version is not valid version string" )
354- hasHeaders := false
355- if container .Config .Tty == false {
356- if currentAPI .Compare (earliestAPI ) >= 0 {
357- hasHeaders = true
358- }
359- }
360- debug ("hasHeaders set to: " , hasHeaders )
361-
349+ func newContainerPump (container * docker.Container , stdout , stderr io.Reader ) * containerPump {
362350 cp := & containerPump {
363351 container : container ,
364352 logstreams : make (map [chan * Message ]* Route ),
365353 }
366- pump := func (source string , hasHeaders bool , input io.Reader ) {
354+ pump := func (source string , input io.Reader ) {
367355 buf := bufio .NewReader (input )
368356 for {
369- // Discard header bytes from log message if TTY is false and api > 1.13.
370- if hasHeaders {
371- buf .Discard (8 )
372- }
373357 line , err := buf .ReadString ('\n' )
374358 if err != nil {
375359 if err != io .EOF {
@@ -385,8 +369,8 @@ func newContainerPump(container *docker.Container, dockerVersion *docker.Env, st
385369 })
386370 }
387371 }
388- go pump ("stdout" , hasHeaders , stdout )
389- go pump ("stderr" , hasHeaders , stderr )
372+ go pump ("stdout" , stdout )
373+ go pump ("stderr" , stderr )
390374 return cp
391375}
392376
0 commit comments