Skip to content

feat: Add --print-debug flag to control debug log output#97

Merged
thiagoralves merged 3 commits into
developmentfrom
claude/disable-debug-logs-PyoXM
Jan 30, 2026
Merged

feat: Add --print-debug flag to control debug log output#97
thiagoralves merged 3 commits into
developmentfrom
claude/disable-debug-logs-PyoXM

Conversation

@thiagoralves
Copy link
Copy Markdown
Contributor

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

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
@thiagoralves thiagoralves requested a review from Copilot January 30, 2026 02:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 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-debug command-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.

Comment thread core/src/plc_app/plc_main.c Outdated
Comment on lines 47 to 50
if (strcmp(argv[i], "--print-debug") == 0)
{
print_debug = true;
}
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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;
}

Copilot uses AI. Check for mistakes.
Comment thread webserver/logger/__init__.py Outdated
Comment on lines 43 to 48
else:
# Update existing StreamHandler level
for h in logger.handlers:
if isinstance(h, logging.StreamHandler) and not isinstance(h, BufferHandler):
h.setLevel(effective_level)

Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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)

Copilot uses AI. Check for mistakes.
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
@thiagoralves thiagoralves changed the base branch from main to development January 30, 2026 02:43
@thiagoralves thiagoralves merged commit 1e66782 into development Jan 30, 2026
1 check failed
@thiagoralves thiagoralves deleted the claude/disable-debug-logs-PyoXM branch January 30, 2026 02:43
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.

3 participants