compose icon indicating copy to clipboard operation
compose copied to clipboard

[BUG] ANSI escape color formatting lost on multiple lines in logs

Open ras0q opened this issue 8 months ago • 2 comments

Description

When a service outputs text with ANSI escape codes for color formatting across multiple lines, docker compose logs only preserves the color for the first line. Subsequent lines are displayed without the indended color.

Expected Actual
Image Image

Steps To Reproduce

Write the following code and execute docker compose up

# compose.yaml
services:
  app:
    image: bash
    command: echo -e "\\e[31m This line is RED.\\n This line is also RED.\\n This span is ... \\e[34m BLUE."

Compose Version

$ docker compose version
Docker Compose version v2.23.3

Docker Environment

$ docker info
Client: Docker Engine - Community
 Version:    28.0.1
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.21.1
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.23.3
    Path:     /home/ras/.docker/cli-plugins/docker-compose

Server:
 Containers: 101
  Running: 0
  Paused: 0
  Stopped: 101
 Images: 111
 Server Version: 28.0.1
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: bcc810d6b9066471b0b6fa75f557a15a1cbf31bb
 runc version: v1.2.4-0-g6c52b3f
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 5.15.133.1-microsoft-standard-WSL2
 Operating System: Ubuntu 22.04.5 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 7.648GiB
 Name: asymp
 ID: 80909571-03a9-44bc-9158-3ca493dc5171
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  ::1/128
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

No response

ras0q avatar Apr 28 '25 14:04 ras0q

Container log to use ANSI sequence obviously conflicts with Compose own formatter to set output. As compose treats logs line by line, it must at least repeat this formatting on each and every line. IMHO we should not try to support such a corner case. How would you expect compose to behave if container uses ANSI sequence to move cursor ?

ndeloof avatar Apr 28 '25 16:04 ndeloof

Thank you for your response. To clarify, in this issue, I was not considering cursor movement or screen manipulation, only text style. But even in that case, it is possible to apply multiple styles, such as underline and bold. If we consider that too, the implementation may be more complex than I initially thought. In such cases, it would be necessary to correctly maintain and reproduce these multiple ANSI escape sequences on each line...

ras0q avatar Apr 30 '25 15:04 ras0q