set terminal in character mode when attached to a container

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2021-03-24 15:37:08 +01:00
parent 9f81314124
commit d4a8e92f46
No known key found for this signature in database
GPG key ID: 9858809D6F8F6E7E
5 changed files with 44 additions and 14 deletions

View file

@ -62,7 +62,7 @@ func (a *allowListLogConsumer) Register(name string) {
}
// GetWriter creates a io.Writer that will actually split by line and format by LogConsumer
func GetWriter(container, service string, events compose.ContainerEventListener) io.Writer {
func GetWriter(container, service string, events compose.ContainerEventListener) io.WriteCloser {
return &splitBuffer{
buffer: bytes.Buffer{},
service: service,
@ -100,3 +100,17 @@ func (s *splitBuffer) Write(b []byte) (int, error) {
}
return n, nil
}
func (s *splitBuffer) Close() error {
b := s.buffer.Bytes()
if len(b) == 0 {
return nil
}
s.consumer(compose.ContainerEvent{
Type: compose.ContainerEventLog,
Service: s.service,
Container: s.container,
Line: string(b),
})
return nil
}