feat: Add --print-debug flag to control debug log output#97
Conversation
By default, debug-level logs are now disabled (no terminal output, no Unix socket transmission, no REST API exposure). This reduces noise in production environments. When --print-debug is passed to start_openplc.sh, it propagates to both the Python webserver and C runtime, enabling debug logs across all components: - C runtime: Only sets LOG_LEVEL_DEBUG when flag is passed - Python webserver: Sets handler levels to INFO by default, DEBUG with flag - Plugins: Automatically respect the C runtime log level https://claude.ai/code/session_01YaVx8wb6vyPSnyfYW6QYMP
There was a problem hiding this comment.
Pull request overview
This PR introduces a --print-debug flag to control debug-level logging across the OpenPLC runtime. By default, debug logs are now disabled to reduce noise in production environments. When the flag is passed to start_openplc.sh, it propagates through the Python webserver to the C runtime, enabling debug logs across all components.
Changes:
- Added
--print-debugcommand-line argument parsing in the shell script, Python webserver, and C runtime - Modified logger configuration to dynamically set handler levels based on the debug flag
- Updated RuntimeManager to pass the debug flag to subprocess invocations of the C runtime
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| start_openplc.sh | Parses --print-debug argument and passes it to the Python webserver |
| webserver/app.py | Parses --print-debug early and configures LoggerConfig before logger initialization |
| webserver/logger/config.py | Adds print_debug field to LoggerConfig |
| webserver/logger/init.py | Implements dynamic log level adjustment based on print_debug configuration |
| webserver/runtimemanager.py | Accepts and uses print_debug parameter to pass flag to C runtime subprocess |
| core/src/plc_app/plc_main.c | Parses --print-debug argument and conditionally sets debug log level |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (strcmp(argv[i], "--print-debug") == 0) | ||
| { | ||
| print_debug = true; | ||
| } |
There was a problem hiding this comment.
The removal of the 'break' statement after the '--print-logs' check means the loop will continue unnecessarily even after finding the flag. While this doesn't cause incorrect behavior with the new '--print-debug' flag, consider using 'else if' for the second condition or adding a break after both flags are checked to avoid redundant iterations.
| if (strcmp(argv[i], "--print-debug") == 0) | |
| { | |
| print_debug = true; | |
| } | |
| else if (strcmp(argv[i], "--print-debug") == 0) | |
| { | |
| print_debug = true; | |
| } | |
| if (print_logs && print_debug) | |
| { | |
| break; | |
| } |
| else: | ||
| # Update existing StreamHandler level | ||
| for h in logger.handlers: | ||
| if isinstance(h, logging.StreamHandler) and not isinstance(h, BufferHandler): | ||
| h.setLevel(effective_level) | ||
|
|
There was a problem hiding this comment.
The else block updates existing StreamHandler levels, but this only executes when a StreamHandler already exists. If get_logger is called multiple times with different print_debug values after LoggerConfig changes, only subsequent calls will see updated levels. Consider always iterating through handlers to update levels, not just in the else branch, to ensure consistency when the configuration changes at runtime.
| else: | |
| # Update existing StreamHandler level | |
| for h in logger.handlers: | |
| if isinstance(h, logging.StreamHandler) and not isinstance(h, BufferHandler): | |
| h.setLevel(effective_level) | |
| # Update all existing StreamHandler levels to match the effective level | |
| for h in logger.handlers: | |
| if isinstance(h, logging.StreamHandler) and not isinstance(h, BufferHandler): | |
| h.setLevel(effective_level) |
Instead of parsing specific arguments in the bash script, forward all command line arguments directly to the Python webserver. This is more generic and allows future arguments to work without script modifications. https://claude.ai/code/session_01YaVx8wb6vyPSnyfYW6QYMP
- C runtime: Use else-if and early break when both flags are found to avoid redundant loop iterations - Python logger: Always update handler levels consistently regardless of whether handlers already exist, ensuring config changes are properly reflected https://claude.ai/code/session_01YaVx8wb6vyPSnyfYW6QYMP
By default, debug-level logs are now disabled (no terminal output, no
Unix socket transmission, no REST API exposure). This reduces noise in
production environments.
When --print-debug is passed to start_openplc.sh, it propagates to both
the Python webserver and C runtime, enabling debug logs across all
components:
https://claude.ai/code/session_01YaVx8wb6vyPSnyfYW6QYMP