Add shim log format configuration#245
Open
austinvazquez wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
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
Formattype plusresolveFormatandSHIM_LOG_FORMAToverride to choose between text and JSON output. - Updates
SetupShimLogto selectslog.NewJSONHandlervsslog.NewTextHandlerbased 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.
0f23a59 to
66608a1
Compare
66608a1 to
e812eb3
Compare
e812eb3 to
3a5f967
Compare
3a5f967 to
d0523d1
Compare
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
d0523d1 to
97a1929
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
I have a use-case where the shim logs (shim, vminitd, and kmesg) are being wrapped at the containerd runtime level.
i.e.
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.