mirror of
https://github.com/docker/compose.git
synced 2026-02-09 01:59:22 +08:00
from Compose CLI, we know the streams used to configure LogConsumer
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
committed by
Guillaume Lours
parent
d70bb8cf5e
commit
fc2a7d13fa
@@ -22,6 +22,7 @@ import (
|
||||
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/compose/v2/pkg/compose"
|
||||
"github.com/docker/compose/v2/pkg/progress"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/docker/compose/v2/cmd/formatter"
|
||||
@@ -90,8 +91,7 @@ func runLogs(ctx context.Context, dockerCli command.Cli, backendOptions *Backend
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
outStream, errStream, _ := backend.GetConfiguredStreams()
|
||||
consumer := formatter.NewLogConsumer(ctx, outStream, errStream, !opts.noColor, !opts.noPrefix, false)
|
||||
consumer := formatter.NewLogConsumer(ctx, dockerCli.Out(), dockerCli.Err(), !opts.noColor, !opts.noPrefix, false)
|
||||
return backend.Logs(ctx, name, consumer, api.LogOptions{
|
||||
Project: project,
|
||||
Services: services,
|
||||
@@ -103,3 +103,32 @@ func runLogs(ctx context.Context, dockerCli command.Cli, backendOptions *Backend
|
||||
Timestamps: opts.timestamps,
|
||||
})
|
||||
}
|
||||
|
||||
var _ api.LogConsumer = &logConsumer{}
|
||||
|
||||
type logConsumer struct {
|
||||
events progress.EventProcessor
|
||||
}
|
||||
|
||||
func (l logConsumer) Log(containerName, message string) {
|
||||
l.events.On(progress.Event{
|
||||
ID: containerName,
|
||||
Text: message,
|
||||
})
|
||||
}
|
||||
|
||||
func (l logConsumer) Err(containerName, message string) {
|
||||
l.events.On(progress.Event{
|
||||
ID: containerName,
|
||||
Status: progress.Error,
|
||||
Text: message,
|
||||
})
|
||||
}
|
||||
|
||||
func (l logConsumer) Status(containerName, message string) {
|
||||
l.events.On(progress.Event{
|
||||
ID: containerName,
|
||||
Status: progress.Error,
|
||||
Text: message,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -296,8 +296,7 @@ func runUp(
|
||||
var consumer api.LogConsumer
|
||||
var attach []string
|
||||
if !upOptions.Detach {
|
||||
outStream, errStream, _ := backend.GetConfiguredStreams()
|
||||
consumer = formatter.NewLogConsumer(ctx, outStream, errStream, !upOptions.noColor, !upOptions.noPrefix, upOptions.timestamp)
|
||||
consumer = formatter.NewLogConsumer(ctx, dockerCli.Out(), dockerCli.Err(), !upOptions.noColor, !upOptions.noPrefix, upOptions.timestamp)
|
||||
|
||||
var attachSet utils.Set[string]
|
||||
if len(upOptions.attach) != 0 {
|
||||
|
||||
@@ -122,8 +122,7 @@ func runWatch(ctx context.Context, dockerCli command.Cli, backendOptions *Backen
|
||||
}
|
||||
}
|
||||
|
||||
outStream, errStream, _ := backend.GetConfiguredStreams()
|
||||
consumer := formatter.NewLogConsumer(ctx, outStream, errStream, false, false, false)
|
||||
consumer := formatter.NewLogConsumer(ctx, dockerCli.Out(), dockerCli.Err(), false, false, false)
|
||||
return backend.Watch(ctx, project, api.WatchOptions{
|
||||
Build: &build,
|
||||
LogTo: consumer,
|
||||
|
||||
Reference in New Issue
Block a user