Skip to content

Commit fc2a7d1

Browse files
ndeloofglours
authored andcommitted
from Compose CLI, we know the streams used to configure LogConsumer
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent d70bb8c commit fc2a7d1

File tree

6 files changed

+33
-31
lines changed

6 files changed

+33
-31
lines changed

cmd/compose/logs.go

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"github.com/docker/cli/cli/command"
2424
"github.com/docker/compose/v2/pkg/compose"
25+
"github.com/docker/compose/v2/pkg/progress"
2526
"github.com/spf13/cobra"
2627

2728
"github.com/docker/compose/v2/cmd/formatter"
@@ -90,8 +91,7 @@ func runLogs(ctx context.Context, dockerCli command.Cli, backendOptions *Backend
9091
if err != nil {
9192
return err
9293
}
93-
outStream, errStream, _ := backend.GetConfiguredStreams()
94-
consumer := formatter.NewLogConsumer(ctx, outStream, errStream, !opts.noColor, !opts.noPrefix, false)
94+
consumer := formatter.NewLogConsumer(ctx, dockerCli.Out(), dockerCli.Err(), !opts.noColor, !opts.noPrefix, false)
9595
return backend.Logs(ctx, name, consumer, api.LogOptions{
9696
Project: project,
9797
Services: services,
@@ -103,3 +103,32 @@ func runLogs(ctx context.Context, dockerCli command.Cli, backendOptions *Backend
103103
Timestamps: opts.timestamps,
104104
})
105105
}
106+
107+
var _ api.LogConsumer = &logConsumer{}
108+
109+
type logConsumer struct {
110+
events progress.EventProcessor
111+
}
112+
113+
func (l logConsumer) Log(containerName, message string) {
114+
l.events.On(progress.Event{
115+
ID: containerName,
116+
Text: message,
117+
})
118+
}
119+
120+
func (l logConsumer) Err(containerName, message string) {
121+
l.events.On(progress.Event{
122+
ID: containerName,
123+
Status: progress.Error,
124+
Text: message,
125+
})
126+
}
127+
128+
func (l logConsumer) Status(containerName, message string) {
129+
l.events.On(progress.Event{
130+
ID: containerName,
131+
Status: progress.Error,
132+
Text: message,
133+
})
134+
}

cmd/compose/up.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,7 @@ func runUp(
296296
var consumer api.LogConsumer
297297
var attach []string
298298
if !upOptions.Detach {
299-
outStream, errStream, _ := backend.GetConfiguredStreams()
300-
consumer = formatter.NewLogConsumer(ctx, outStream, errStream, !upOptions.noColor, !upOptions.noPrefix, upOptions.timestamp)
299+
consumer = formatter.NewLogConsumer(ctx, dockerCli.Out(), dockerCli.Err(), !upOptions.noColor, !upOptions.noPrefix, upOptions.timestamp)
301300

302301
var attachSet utils.Set[string]
303302
if len(upOptions.attach) != 0 {

cmd/compose/watch.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ func runWatch(ctx context.Context, dockerCli command.Cli, backendOptions *Backen
122122
}
123123
}
124124

125-
outStream, errStream, _ := backend.GetConfiguredStreams()
126-
consumer := formatter.NewLogConsumer(ctx, outStream, errStream, false, false, false)
125+
consumer := formatter.NewLogConsumer(ctx, dockerCli.Out(), dockerCli.Err(), false, false, false)
127126
return backend.Watch(ctx, project, api.WatchOptions{
128127
Build: &build,
129128
LogTo: consumer,

pkg/api/api.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,6 @@ type Compose interface {
140140
Generate(ctx context.Context, options GenerateOptions) (*types.Project, error)
141141
// Volumes executes the equivalent to a `docker volume ls`
142142
Volumes(ctx context.Context, project string, options VolumesOptions) ([]VolumesSummary, error)
143-
// GetConfiguredStreams returns the configured I/O streams (stdout, stderr, stdin).
144-
// If no custom streams were configured, it returns the dockerCli streams.
145-
GetConfiguredStreams() (stdout io.Writer, stderr io.Writer, stdin io.Reader)
146143
// LoadProject loads and validates a Compose project from configuration files.
147144
LoadProject(ctx context.Context, options ProjectLoadOptions) (*types.Project, error)
148145
}

pkg/compose/compose.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,6 @@ func (s *composeService) stdinfo() *streams.Out {
285285
return s.stderr()
286286
}
287287

288-
// GetConfiguredStreams returns the configured I/O streams (implements api.Compose interface)
289-
func (s *composeService) GetConfiguredStreams() (io.Writer, io.Writer, io.Reader) {
290-
return s.stdout(), s.stderr(), s.stdin()
291-
}
292-
293288
// readCloserAdapter adapts io.Reader to io.ReadCloser
294289
type readCloserAdapter struct {
295290
r io.Reader

pkg/mocks/mock_docker_compose_api.go

Lines changed: 0 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)