mirror of
https://github.com/docker/compose.git
synced 2026-08-27 03:45:29 +00:00
introduce compose logs --tail and --follow options
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
24b5aeaa32
commit
7d0e1dfc3c
8 changed files with 25 additions and 10 deletions
|
|
@ -97,7 +97,7 @@ func Command(contextType string) *cobra.Command {
|
|||
stopCommand(&opts),
|
||||
psCommand(&opts),
|
||||
listCommand(),
|
||||
logsCommand(&opts),
|
||||
logsCommand(&opts, contextType),
|
||||
convertCommand(&opts),
|
||||
runCommand(&opts),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -24,15 +24,18 @@ import (
|
|||
|
||||
"github.com/docker/compose-cli/api/client"
|
||||
"github.com/docker/compose-cli/api/compose"
|
||||
"github.com/docker/compose-cli/api/context/store"
|
||||
"github.com/docker/compose-cli/cli/formatter"
|
||||
)
|
||||
|
||||
type logsOptions struct {
|
||||
*projectOptions
|
||||
composeOptions
|
||||
follow bool
|
||||
tail string
|
||||
}
|
||||
|
||||
func logsCommand(p *projectOptions) *cobra.Command {
|
||||
func logsCommand(p *projectOptions, contextType string) *cobra.Command {
|
||||
opts := logsOptions{
|
||||
projectOptions: p,
|
||||
}
|
||||
|
|
@ -43,6 +46,10 @@ func logsCommand(p *projectOptions) *cobra.Command {
|
|||
return runLogs(cmd.Context(), opts, args)
|
||||
},
|
||||
}
|
||||
logsCmd.Flags().BoolVarP(&opts.follow, "follow", "f", false, "Follow log output.")
|
||||
if contextType == store.DefaultContextType {
|
||||
logsCmd.Flags().StringVar(&opts.tail, "tail", "all", "Number of lines to show from the end of the logs for each container.")
|
||||
}
|
||||
return logsCmd
|
||||
}
|
||||
|
||||
|
|
@ -59,5 +66,7 @@ func runLogs(ctx context.Context, opts logsOptions, services []string) error {
|
|||
consumer := formatter.NewLogConsumer(ctx, os.Stdout)
|
||||
return c.ComposeService().Logs(ctx, projectName, consumer, compose.LogOptions{
|
||||
Services: services,
|
||||
Follow: opts.follow,
|
||||
Tail: opts.tail,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue