Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker logs -t needs to strip carriage return character to show timestamp #49076

Open
bluepuma77 opened this issue Dec 12, 2024 · 0 comments
Open
Labels
kind/bug Bugs are bugs. The cause may or may not be known at triage time so debugging may be needed. status/0-triage

Comments

@bluepuma77
Copy link

bluepuma77 commented Dec 12, 2024

Description

docker logs -t should prefix every log line with a timestamp like 2024-12-12T10:47:47.310209758Z.

When the container is using \n\r at the end of a log line (or \r at beginning), then the timestamp is overwritten and not shown.

2024-12-12T11:25:38.363477610Z There are only two hard things in computer science:
cache invalidation and naming things.
2024-12-12T11:25:38.363527859Z

docker logs should probably strip the /r, at least when used with -t option, maybe just on Linux.

The issue happens for example with containers based on mcr.microsoft.com/mssql/server:2022-latest image on Linux.

See discussion on Docker Community Forum.

Reproduce

docker run -d --name t1 bash echo -e "There are only two hard things in computer science: \ncache invalidation and naming things.\n"
docker logs -t t1
docker rm t1

docker run -d --name t2 bash echo -e "There are only two hard things in computer science: \r\ncache invalidation and naming things.\r\n"
docker logs -t t2
docker rm t2

docker run -d --name t3 bash echo -e "There are only two hard things in computer science: \n\rcache invalidation and naming things.\n\r"
docker logs -t t3
docker rm t3

outputs

2024-12-12T11:25:37.492133962Z There are only two hard things in computer science:
2024-12-12T11:25:37.492317272Z cache invalidation and naming things.
2024-12-12T11:25:37.492330714Z

2024-12-12T11:25:37.932053082Z There are only two hard things in computer science:
2024-12-12T11:25:37.932101138Z cache invalidation and naming things.
2024-12-12T11:25:37.932106578Z

2024-12-12T11:25:38.363477610Z There are only two hard things in computer science:
cache invalidation and naming things.
2024-12-12T11:25:38.363527859Z

The last example has an overwritten timestamp

Expected behavior

The timestamp should always be shown, irrespectively of the log line content.

docker version

# docker version
Client: Docker Engine - Community
 Version:           27.4.0
 API version:       1.47
 Go version:        go1.22.10
 Git commit:        bde2b89
 Built:             Sat Dec  7 10:38:55 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          27.4.0
  API version:      1.47 (minimum version 1.24)
  Go version:       go1.22.10
  Git commit:       92a8393
  Built:            Sat Dec  7 10:38:55 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.7.24
  GitCommit:        88bf19b2105c8b17560993bee28a01ddc2f97182
 runc:
  Version:          1.2.2
  GitCommit:        v1.2.2-0-g7cb3632
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker info

# docker info
Client: Docker Engine - Community
 Version:    27.4.0
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.19.2
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.31.0
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 19
  Running: 16
  Paused: 0
  Stopped: 3
 Images: 52
 Server Version: 27.4.0
 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: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 88bf19b2105c8b17560993bee28a01ddc2f97182
 runc version: v1.2.2-0-g7cb3632
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.8.0-50-generic
 Operating System: Ubuntu 24.04.1 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 15.25GiB
 Name: myhost
 ID: d0b46f47-c57e-4b70-bdfe-39a9f8e01234
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled

Additional Info

No response

@bluepuma77 bluepuma77 added kind/bug Bugs are bugs. The cause may or may not be known at triage time so debugging may be needed. status/0-triage labels Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Bugs are bugs. The cause may or may not be known at triage time so debugging may be needed. status/0-triage
Projects
None yet
Development

No branches or pull requests

1 participant