mirror of
https://github.com/docker/compose.git
synced 2026-08-31 06:49:15 +00:00
Merge pull request #1015 from docker/logConsumer
Revisit logs/up API to pass a LogConsumer vs io.Writer
This commit is contained in:
commit
576aa46d21
11 changed files with 110 additions and 97 deletions
|
|
@ -20,9 +20,10 @@ import (
|
|||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/docker/compose-cli/api/client"
|
||||
"github.com/docker/compose-cli/formatter"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func logsCommand() *cobra.Command {
|
||||
|
|
@ -50,5 +51,6 @@ func runLogs(ctx context.Context, opts composeOptions) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return c.ComposeService().Logs(ctx, projectName, os.Stdout)
|
||||
consumer := formatter.NewLogConsumer(ctx, os.Stdout)
|
||||
return c.ComposeService().Logs(ctx, projectName, consumer)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,16 +20,17 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/docker/compose-cli/api/client"
|
||||
"github.com/docker/compose-cli/api/compose"
|
||||
"github.com/docker/compose-cli/context/store"
|
||||
"github.com/docker/compose-cli/formatter"
|
||||
"github.com/docker/compose-cli/progress"
|
||||
|
||||
"github.com/compose-spec/compose-go/cli"
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/docker/compose-cli/api/client"
|
||||
"github.com/docker/compose-cli/context/store"
|
||||
"github.com/docker/compose-cli/progress"
|
||||
)
|
||||
|
||||
func upCommand(contextType string) *cobra.Command {
|
||||
|
|
@ -83,12 +84,12 @@ func runCreateStart(ctx context.Context, opts composeOptions, services []string)
|
|||
return err
|
||||
}
|
||||
|
||||
var w io.Writer
|
||||
var consumer compose.LogConsumer
|
||||
if !opts.Detach {
|
||||
w = os.Stdout
|
||||
consumer = formatter.NewLogConsumer(ctx, os.Stdout)
|
||||
}
|
||||
|
||||
err = c.ComposeService().Start(ctx, project, w)
|
||||
err = c.ComposeService().Start(ctx, project, consumer)
|
||||
if errors.Is(ctx.Err(), context.Canceled) {
|
||||
fmt.Println("Gracefully stopping...")
|
||||
ctx = context.Background()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue