@@ -23,11 +23,13 @@ import (
2323 "io"
2424 "strconv"
2525 "strings"
26+
27+ "github.com/docker/compose-cli/api/compose"
2628)
2729
2830// NewLogConsumer creates a new LogConsumer
29- func NewLogConsumer (ctx context.Context , w io.Writer ) LogConsumer {
30- return LogConsumer {
31+ func NewLogConsumer (ctx context.Context , w io.Writer ) compose. LogConsumer {
32+ return & logConsumer {
3133 ctx : ctx ,
3234 colors : map [string ]colorFunc {},
3335 width : 0 ,
@@ -36,7 +38,7 @@ func NewLogConsumer(ctx context.Context, w io.Writer) LogConsumer {
3638}
3739
3840// Log formats a log message as received from service/container
39- func (l * LogConsumer ) Log (service , container , message string ) {
41+ func (l * logConsumer ) Log (service , container , message string ) {
4042 if l .ctx .Err () != nil {
4143 return
4244 }
@@ -54,16 +56,7 @@ func (l *LogConsumer) Log(service, container, message string) {
5456 }
5557}
5658
57- // GetWriter creates a io.Writer that will actually split by line and format by LogConsumer
58- func (l * LogConsumer ) GetWriter (service , container string ) io.Writer {
59- return splitBuffer {
60- service : service ,
61- container : container ,
62- consumer : l ,
63- }
64- }
65-
66- func (l * LogConsumer ) computeWidth () {
59+ func (l * logConsumer ) computeWidth () {
6760 width := 0
6861 for n := range l .colors {
6962 if len (n ) > width {
@@ -74,25 +67,9 @@ func (l *LogConsumer) computeWidth() {
7467}
7568
7669// LogConsumer consume logs from services and format them
77- type LogConsumer struct {
70+ type logConsumer struct {
7871 ctx context.Context
7972 colors map [string ]colorFunc
8073 width int
8174 writer io.Writer
8275}
83-
84- type splitBuffer struct {
85- service string
86- container string
87- consumer * LogConsumer
88- }
89-
90- func (s splitBuffer ) Write (b []byte ) (n int , err error ) {
91- split := bytes .Split (b , []byte {'\n' })
92- for _ , line := range split {
93- if len (line ) != 0 {
94- s .consumer .Log (s .service , s .container , string (line ))
95- }
96- }
97- return len (b ), nil
98- }
0 commit comments