mirror of
https://github.com/docker/compose.git
synced 2026-08-04 14:47:40 +00:00
allow to collect logs for a subset of project services
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
ba47b3d9d2
commit
056dfb95bc
8 changed files with 60 additions and 12 deletions
|
|
@ -21,18 +21,18 @@ import (
|
|||
"os"
|
||||
|
||||
"github.com/docker/compose-cli/api/client"
|
||||
"github.com/docker/compose-cli/api/compose"
|
||||
"github.com/docker/compose-cli/formatter"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func logsCommand() *cobra.Command {
|
||||
opts := composeOptions{}
|
||||
logsCmd := &cobra.Command{
|
||||
Use: "logs",
|
||||
Use: "logs [service...]",
|
||||
Short: "View output from containers",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runLogs(cmd.Context(), opts)
|
||||
return runLogs(cmd.Context(), opts, args)
|
||||
},
|
||||
}
|
||||
logsCmd.Flags().StringVarP(&opts.Name, "project-name", "p", "", "Project name")
|
||||
|
|
@ -42,7 +42,7 @@ func logsCommand() *cobra.Command {
|
|||
return logsCmd
|
||||
}
|
||||
|
||||
func runLogs(ctx context.Context, opts composeOptions) error {
|
||||
func runLogs(ctx context.Context, opts composeOptions, services []string) error {
|
||||
c, err := client.NewWithDefaultLocalBackend(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -53,5 +53,7 @@ func runLogs(ctx context.Context, opts composeOptions) error {
|
|||
return err
|
||||
}
|
||||
consumer := formatter.NewLogConsumer(ctx, os.Stdout)
|
||||
return c.ComposeService().Logs(ctx, projectName, consumer)
|
||||
return c.ComposeService().Logs(ctx, projectName, consumer, compose.LogOptions{
|
||||
Services: services,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue