From 3976abcdc1ed7096a465a3c23ef201662055ebf1 Mon Sep 17 00:00:00 2001 From: Afshin Paydar Date: Tue, 15 Jun 2021 00:14:30 +0800 Subject: [PATCH 1/2] As docker logs defines --since option to limit the amount of logs to retrieve from container's history This changes will add docker compose logs --since option Signed-off-by: Afshin Paydar --- api/compose/api.go | 1 + cli/cmd/compose/logs.go | 3 +++ local/compose/logs.go | 1 + 3 files changed, 5 insertions(+) diff --git a/api/compose/api.go b/api/compose/api.go index b63c244f..1d8c0d42 100644 --- a/api/compose/api.go +++ b/api/compose/api.go @@ -324,6 +324,7 @@ type ServiceStatus struct { type LogOptions struct { Services []string Tail string + Since string Follow bool Timestamps bool } diff --git a/cli/cmd/compose/logs.go b/cli/cmd/compose/logs.go index f89b13b4..56d5ef38 100644 --- a/cli/cmd/compose/logs.go +++ b/cli/cmd/compose/logs.go @@ -32,6 +32,7 @@ type logsOptions struct { composeOptions follow bool tail string + since string noColor bool noPrefix bool timestamps bool @@ -50,6 +51,7 @@ func logsCommand(p *projectOptions, contextType string, backend compose.Service) } flags := logsCmd.Flags() flags.BoolVarP(&opts.follow, "follow", "f", false, "Follow log output.") + flags.StringVar(&opts.since, "since", "", "Show logs since timestamp (e.g. 2013-01-02T13:23:37 or 42m)") flags.BoolVar(&opts.noColor, "no-color", false, "Produce monochrome output.") flags.BoolVar(&opts.noPrefix, "no-log-prefix", false, "Don't print prefix in logs.") flags.BoolVarP(&opts.timestamps, "timestamps", "t", false, "Show timestamps.") @@ -70,6 +72,7 @@ func runLogs(ctx context.Context, backend compose.Service, opts logsOptions, ser Services: services, Follow: opts.follow, Tail: opts.tail, + Since: opts.since, Timestamps: opts.timestamps, }) } diff --git a/local/compose/logs.go b/local/compose/logs.go index 3d0323fc..759eccc6 100644 --- a/local/compose/logs.go +++ b/local/compose/logs.go @@ -48,6 +48,7 @@ func (s *composeService) Logs(ctx context.Context, projectName string, consumer ShowStdout: true, ShowStderr: true, Follow: options.Follow, + Since: options.Since, Tail: options.Tail, Timestamps: options.Timestamps, }) From bbaccb43394e85310fc6003feeaa40c284b254dc Mon Sep 17 00:00:00 2001 From: Afshin Paydar Date: Wed, 16 Jun 2021 08:55:53 +0800 Subject: [PATCH 2/2] Add docker compose logs --until option Signed-off-by: Afshin Paydar --- api/compose/api.go | 1 + cli/cmd/compose/logs.go | 5 ++++- local/compose/logs.go | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/api/compose/api.go b/api/compose/api.go index 1d8c0d42..50067442 100644 --- a/api/compose/api.go +++ b/api/compose/api.go @@ -325,6 +325,7 @@ type LogOptions struct { Services []string Tail string Since string + Until string Follow bool Timestamps bool } diff --git a/cli/cmd/compose/logs.go b/cli/cmd/compose/logs.go index 56d5ef38..5722ca3c 100644 --- a/cli/cmd/compose/logs.go +++ b/cli/cmd/compose/logs.go @@ -33,6 +33,7 @@ type logsOptions struct { follow bool tail string since string + until string noColor bool noPrefix bool timestamps bool @@ -51,7 +52,8 @@ func logsCommand(p *projectOptions, contextType string, backend compose.Service) } flags := logsCmd.Flags() flags.BoolVarP(&opts.follow, "follow", "f", false, "Follow log output.") - flags.StringVar(&opts.since, "since", "", "Show logs since timestamp (e.g. 2013-01-02T13:23:37 or 42m)") + flags.StringVar(&opts.since, "since", "", "Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)") + flags.StringVar(&opts.until, "until", "", "Show logs before a timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)") flags.BoolVar(&opts.noColor, "no-color", false, "Produce monochrome output.") flags.BoolVar(&opts.noPrefix, "no-log-prefix", false, "Don't print prefix in logs.") flags.BoolVarP(&opts.timestamps, "timestamps", "t", false, "Show timestamps.") @@ -73,6 +75,7 @@ func runLogs(ctx context.Context, backend compose.Service, opts logsOptions, ser Follow: opts.follow, Tail: opts.tail, Since: opts.since, + Until: opts.until, Timestamps: opts.timestamps, }) } diff --git a/local/compose/logs.go b/local/compose/logs.go index 759eccc6..560fcf07 100644 --- a/local/compose/logs.go +++ b/local/compose/logs.go @@ -49,6 +49,7 @@ func (s *composeService) Logs(ctx context.Context, projectName string, consumer ShowStderr: true, Follow: options.Follow, Since: options.Since, + Until: options.Until, Tail: options.Tail, Timestamps: options.Timestamps, })