From b31957c7d6663c9300fcf5602cdfc862d9a0b38f Mon Sep 17 00:00:00 2001 From: pnkcaht Date: Sat, 24 Jan 2026 14:42:15 -0500 Subject: [PATCH 1/2] fix: respect quiet mode in 'docker compose up' Signed-off-by: pnkcaht --- pkg/compose/up.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/compose/up.go b/pkg/compose/up.go index d5eb4d8769..442ebd9c10 100644 --- a/pkg/compose/up.go +++ b/pkg/compose/up.go @@ -102,7 +102,20 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options navigationMenu.EnableWatch(options.Start.Watch, watcher) } - printer := newLogPrinter(logConsumer) + // Detect if the user requested quiet mode + // logConsumer is nil when --progress quiet or --no-log-prefix is used + quiet := logConsumer == nil + + var printer logPrinter // <--- sem o * + + if quiet { + // Create a "silent" printer that ignores normal logs + // Only critical events like container errors or exit code != 0 will be printed + printer = newLogPrinter(nil) // mantém simples pra não dar erro de tipo + } else { + // Normal printer that writes all logs to the terminal + printer = newLogPrinter(logConsumer) + } // global context to handle canceling goroutines globalCtx, cancel := context.WithCancel(ctx) From 503d5d10f17fd8999889d81cb2bc237f464a3dae Mon Sep 17 00:00:00 2001 From: pnkcaht Date: Sat, 24 Jan 2026 15:11:44 -0500 Subject: [PATCH 2/2] feat: implement quiet mode log consumer for up command Signed-off-by: pnkcaht --- pkg/compose/up.go | 53 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/pkg/compose/up.go b/pkg/compose/up.go index 442ebd9c10..a9fac710bc 100644 --- a/pkg/compose/up.go +++ b/pkg/compose/up.go @@ -39,6 +39,36 @@ import ( "github.com/docker/compose/v5/pkg/api" ) +// quietLogConsumer implements api.LogConsumer for --progress quiet or --no-log-prefix +// It suppresses normal logs and only outputs critical events (container errors or non-zero exit codes) +type quietLogConsumer struct{} + +// HandleEvent processes container events. Only prints containers that exited with a non-zero exit code +func (q *quietLogConsumer) HandleEvent(event api.ContainerEvent) { + if event.Type == api.ContainerEventExited && event.ExitCode != 0 { + // Print to stderr to separate from normal output streams + fmt.Fprintf(os.Stderr, "%s exited with code %d\n", event.Service, event.ExitCode) + } +} + +// Log is called for standard container log messages +// This implementation discards all logs to keep quiet mode truly silent +func (q *quietLogConsumer) Log(service, msg string) { + // No-op: suppress normal logs +} + +// Err is called for critical error messages related to a service +// In quiet mode, we still want to print these to stderr +func (q *quietLogConsumer) Err(service, msg string) { + fmt.Fprintf(os.Stderr, "%s: %s\n", service, msg) +} + +// Status is called for status updates (like container starting/stopping) +// These updates are ignored in quiet mode to minimize output noise +func (q *quietLogConsumer) Status(service, msg string) { + // No-op: suppress status messages +} + func (s *composeService) Up(ctx context.Context, project *types.Project, options api.UpOptions) error { //nolint:gocyclo err := Run(ctx, tracing.SpanWrapFunc("project/up", tracing.ProjectOptions(ctx, project), func(ctx context.Context) error { err := s.create(ctx, project, options.Create) @@ -101,26 +131,27 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options if navigationMenu != nil && watcher != nil { navigationMenu.EnableWatch(options.Start.Watch, watcher) } - - // Detect if the user requested quiet mode - // logConsumer is nil when --progress quiet or --no-log-prefix is used + // Determine if quiet mode is requested + // In quiet mode, logConsumer is nil because --progress=quiet or --no-log-prefix was used quiet := logConsumer == nil - var printer logPrinter // <--- sem o * - + // Create the appropriate log printer based on quiet mode + var printer logPrinter if quiet { - // Create a "silent" printer that ignores normal logs - // Only critical events like container errors or exit code != 0 will be printed - printer = newLogPrinter(nil) // mantém simples pra não dar erro de tipo + // In quiet mode, use quietLogConsumer that suppresses normal logs + // Only critical events like container errors or non-zero exit codes are printed + printer = newLogPrinter(&quietLogConsumer{}) } else { - // Normal printer that writes all logs to the terminal + // Normal mode: print all container logs to the terminal printer = newLogPrinter(logConsumer) } - // global context to handle canceling goroutines + // Create a global context for controlling goroutines and graceful shutdown globalCtx, cancel := context.WithCancel(ctx) - defer cancel() + defer cancel() // Ensure all goroutines are canceled when Up() exits + // If the interactive navigation menu is enabled, attach it to the cancel function + // This allows detaching from logs gracefully when user presses the detach key if navigationMenu != nil { navigationMenu.EnableDetach(cancel) }