diff --git a/api/compose/api.go b/api/compose/api.go index a482acd13..529737a42 100644 --- a/api/compose/api.go +++ b/api/compose/api.go @@ -218,7 +218,7 @@ type Stack struct { // LogConsumer is a callback to process log messages from services type LogConsumer interface { - Log(name, container, message string) + Log(name, service, container, message string) Status(name, container, msg string) Register(name string, source string) } diff --git a/cli/cmd/compose/up.go b/cli/cmd/compose/up.go index ffe23fcfa..a52ffb09b 100644 --- a/cli/cmd/compose/up.go +++ b/cli/cmd/compose/up.go @@ -347,7 +347,7 @@ func (p printer) run(ctx context.Context, cascadeStop bool, exitCodeFrom string, } case compose.ContainerEventLog: if !aborting { - consumer.Log(event.Name, event.Source, event.Line) + consumer.Log(event.Name, event.Service, event.Source, event.Line) } } } diff --git a/cli/formatter/logs.go b/cli/formatter/logs.go index 3d792123b..bc320954e 100644 --- a/cli/formatter/logs.go +++ b/cli/formatter/logs.go @@ -62,13 +62,13 @@ func (l *logConsumer) register(name string, id string) *presenter { } // Log formats a log message as received from name/container -func (l *logConsumer) Log(name, id, message string) { +func (l *logConsumer) Log(name, service, container, message string) { if l.ctx.Err() != nil { return } - p, ok := l.presenters[id] + p, ok := l.presenters[container] if !ok { // should have been registered, but ¯\_(ツ)_/¯ - p = l.register(name, id) + p = l.register(name, container) } for _, line := range strings.Split(message, "\n") { fmt.Fprintf(l.writer, "%s %s\n", p.prefix, line) // nolint:errcheck diff --git a/ecs/aws.go b/ecs/aws.go index b9e85990b..6e8ba8411 100644 --- a/ecs/aws.go +++ b/ecs/aws.go @@ -63,7 +63,7 @@ type API interface { InspectSecret(ctx context.Context, id string) (secrets.Secret, error) ListSecrets(ctx context.Context) ([]secrets.Secret, error) DeleteSecret(ctx context.Context, id string, recover bool) error - GetLogs(ctx context.Context, name string, consumer func(service string, container string, message string), follow bool) error + GetLogs(ctx context.Context, name string, consumer func(name string, service string, container string, message string), follow bool) error DescribeService(ctx context.Context, cluster string, arn string) (compose.ServiceStatus, error) DescribeServiceTasks(ctx context.Context, cluster string, project string, service string) ([]compose.ContainerSummary, error) getURLWithPortMapping(ctx context.Context, targetGroupArns []string) ([]compose.PortPublisher, error) diff --git a/ecs/aws_mock.go b/ecs/aws_mock.go index d857cda1c..568c60a79 100644 --- a/ecs/aws_mock.go +++ b/ecs/aws_mock.go @@ -285,7 +285,7 @@ func (mr *MockAPIMockRecorder) GetLoadBalancerURL(arg0, arg1 interface{}) *gomoc } // GetLogs mocks base method -func (m *MockAPI) GetLogs(arg0 context.Context, arg1 string, arg2 func(string, string, string), arg3 bool) error { +func (m *MockAPI) GetLogs(arg0 context.Context, arg1 string, arg2 func(string, string, string, string), arg3 bool) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetLogs", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(error) diff --git a/ecs/sdk.go b/ecs/sdk.go index db7fa0911..43a454250 100644 --- a/ecs/sdk.go +++ b/ecs/sdk.go @@ -805,7 +805,7 @@ func (s sdk) DeleteSecret(ctx context.Context, id string, recover bool) error { return err } -func (s sdk) GetLogs(ctx context.Context, name string, consumer func(name string, container string, message string), follow bool) error { +func (s sdk) GetLogs(ctx context.Context, name string, consumer func(name string, service string, container string, message string), follow bool) error { logGroup := fmt.Sprintf("/docker-compose/%s", name) var startTime int64 for { @@ -832,7 +832,7 @@ func (s sdk) GetLogs(ctx context.Context, name string, consumer func(name string for _, event := range events.Events { p := strings.Split(aws.StringValue(event.LogStreamName), "/") - consumer(p[1], p[2], aws.StringValue(event.Message)) + consumer(p[1], p[1], p[2], aws.StringValue(event.Message)) startTime = *event.IngestionTime } } diff --git a/kube/client/client.go b/kube/client/client.go index c0a14dd3b..227688478 100644 --- a/kube/client/client.go +++ b/kube/client/client.go @@ -106,7 +106,7 @@ func (kc *KubeClient) GetLogs(ctx context.Context, projectName string, consumer request := kc.client.CoreV1().Pods(kc.namespace).GetLogs(pod.Name, &corev1.PodLogOptions{Follow: follow}) service := pod.Labels[compose.ServiceTag] w := utils.GetWriter(pod.Name, service, string(pod.UID), func(event compose.ContainerEvent) { - consumer.Log(event.Name, event.Source, event.Line) + consumer.Log(event.Name, event.Service, event.Source, event.Line) }) eg.Go(func() error { diff --git a/local/compose/logs.go b/local/compose/logs.go index 62e3a511f..ae71d30ef 100644 --- a/local/compose/logs.go +++ b/local/compose/logs.go @@ -77,7 +77,7 @@ func (s *composeService) Logs(ctx context.Context, projectName string, consumer } name := getContainerNameWithoutProject(c) w := utils.GetWriter(name, service, c.ID, func(event compose.ContainerEvent) { - consumer.Log(name, event.Name, event.Line) + consumer.Log(name, event.Service, event.Name, event.Line) }) if container.Config.Tty { _, err = io.Copy(w, r) diff --git a/utils/logs.go b/utils/logs.go index 53f3aa0c5..7593f7481 100644 --- a/utils/logs.go +++ b/utils/logs.go @@ -43,9 +43,9 @@ type allowListLogConsumer struct { delegate compose.LogConsumer } -func (a *allowListLogConsumer) Log(name, container, message string) { - if a.allowList[name] { - a.delegate.Log(name, container, message) +func (a *allowListLogConsumer) Log(name, service, container, message string) { + if a.allowList[service] { + a.delegate.Log(name, service, container, message) } }