Skip to content

Add shim log format configuration#245

Open
austinvazquez wants to merge 1 commit into
containerd:mainfrom
austinvazquez:add-shim-logs-format-detection
Open

Add shim log format configuration#245
austinvazquez wants to merge 1 commit into
containerd:mainfrom
austinvazquez:add-shim-logs-format-detection

Conversation

@austinvazquez

@austinvazquez austinvazquez commented Jul 1, 2026

Copy link
Copy Markdown
Member

Context

I have a use-case where the shim logs (shim, vminitd, and kmesg) are being wrapped at the containerd runtime level.

i.e.

{"time":"2026-06-25T19:48:55.894022-05:00","level":"INFO","msg":"time=2026-06-25T19:48:55.893-05:00 level=INFO msg=\"VM connection established\" ns=docker id=eb5effb906647cb675950ac6ecd1b041309ea72ef72d92f68ac20d20f327333c component=shim t_config=117.875µs t_boot=131.007542ms t_total=131.125542ms runtime=io.containerd.nerdbox.v1"}

From looking into this, I believe this is because containerd writes shim logs to os.Stderr using a raw io.Copy (see core/runtime/v2/shim.go) instead of re-logging the shim FIFO output. For this reason, the runtime is having to capture os.Stderr and re-emit.

This change adds shim log options to enable configuration of JSON formatted logs. This will enable a workaround to parse the logs at the containerd runtime level with more simplified parsing.

Copilot AI review requested due to automatic review settings July 1, 2026 21:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds shim log format auto-detection (terminal vs. pipe/FIFO) with an environment variable override so shim logs can be emitted as JSON when needed for containerd-level log wrapping/parsing.

Changes:

  • Introduces a Format type plus resolveFormat and SHIM_LOG_FORMAT override to choose between text and JSON output.
  • Updates SetupShimLog to select slog.NewJSONHandler vs slog.NewTextHandler based on the resolved format.
  • Adds cross-platform isTerminal(io.Writer) helpers (Unix + Windows) and unit tests for the new format resolution and terminal detection.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
pkg/logging/shim_windows.go Adds Windows console detection (GetConsoleMode) to support log format auto-detection.
pkg/logging/shim_unix.go Adds Unix “terminal” detection via file mode to support log format auto-detection.
pkg/logging/logging.go Adds format selection (JSON vs text), env override, and updates shim logger setup accordingly.
pkg/logging/logging_test.go Adds tests for format resolution and isTerminal behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/logging/logging.go Outdated
Comment thread pkg/logging/shim_unix.go Outdated
@austinvazquez austinvazquez force-pushed the add-shim-logs-format-detection branch from 0f23a59 to 66608a1 Compare July 2, 2026 13:43
@austinvazquez austinvazquez changed the title Add shim log format autodetection Add shim log format configuration Jul 2, 2026
Copilot AI review requested due to automatic review settings July 2, 2026 13:57
@austinvazquez austinvazquez force-pushed the add-shim-logs-format-detection branch from 66608a1 to e812eb3 Compare July 2, 2026 13:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread pkg/logging/logging.go Outdated
Comment thread pkg/logging/logging_test.go
@austinvazquez austinvazquez force-pushed the add-shim-logs-format-detection branch from e812eb3 to 3a5f967 Compare July 2, 2026 14:03
Copilot AI review requested due to automatic review settings July 2, 2026 16:36
@austinvazquez austinvazquez force-pushed the add-shim-logs-format-detection branch from 3a5f967 to d0523d1 Compare July 2, 2026 16:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

Comment thread pkg/logging/logging.go
Comment thread pkg/logging/logging.go
Comment thread pkg/logging/logging.go
Comment thread pkg/logging/logging_test.go Outdated
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
@austinvazquez austinvazquez force-pushed the add-shim-logs-format-detection branch from d0523d1 to 97a1929 Compare July 2, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants