feat(logging): Add environment-based logger configuration and cleanup logging init #28
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.
Description
Summary
Currently, there is no way applying env vars related to logging when executing kubectl_mcp_tool.mcp_server.
To solve, this, this PR introduces an improved logging configuration for the MCP server by adding a new utility function,
set_logger_with_envs
, inkubectl_mcp_tool/utils/logging_util.py
.This utility enables logging behaviour (log level, output target) to be controlled via environment variables, making the MCP server easier to debug and operate in various environments.
Changes
New Utility:
set_logger_with_envs(logger)
inkubectl_mcp_tool/utils/logging_util.py
MCP_DEBUG
(takes priority) orKUBECTL_MCP_LOG_LEVEL
MCP_LOG_FILE
(otherwise logs tostderr
)MCP Server:
set_logger_with_envs(logger)
for configurationbasicConfig
usageMotivation
Logging can be controlled per environment without code changes.
Avoids duplicate log output from multiple initializations.
Easily redirect logs and adjust levels for debugging or production.
Moves logger setup into a utility function, preparing for more robust logging improvements.
Test