Logging improvements#99
Merged
Merged
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
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
…PyoXM feat: Add --print-debug flag to control debug log output
Replace JSON output with human-readable format for stdout logs: [YYYY-MM-DD HH:MM:SS] [LEVEL] message - Add HumanReadableFormatter class to formatter.py - Use HumanReadableFormatter for StreamHandler (stdout) - Keep JsonFormatter for BufferHandler (API responses) - Handle both Python-native logs and C runtime JSON logs - Convert Unix timestamps to human-readable datetime This is Phase 1 of the logging normalization effort. API endpoint /api/runtime-logs still returns JSON format. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Phase 2 of logging normalization - convert direct printf/fprintf calls in C code to use the centralized logging system. Files modified: - plugin_driver.c: Convert 73 printf/fprintf calls to log_info/log_error/log_warn/log_debug - plugin_config.c: Convert 2 printf calls to log_debug - plugin_logger.c: Convert init warnings to log_warn, format fallback output - journal_buffer.c: Convert 2 fprintf calls to log_error - plc_main.c: Format early init error with timestamp - watchdog.c: Format critical error with timestamp Fallback logging (when central logging unavailable) now uses human-readable format: [YYYY-MM-DD HH:MM:SS] [LEVEL] message Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
plugin_logger.c is compiled into native plugins, not the main runtime. Using log_warn/log_error directly causes undefined symbol errors when loading plugins. Replace with PLUGIN_LOGGER_STDERR macro that uses fprintf with the human-readable timestamp format. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Convert print() statements in webserver Python files to use the centralized logging system. Files modified: - plugin_config_model.py: 6 print -> logger.info/error/warning - credentials.py: 10 print -> logger.info/error/warning - config.py: 2 print -> logger.info/error - app.py: 2 print -> logger.info Note: Python plugin files (modbus_master_memory.py) need a dedicated logging solution similar to opcua_logging.py and are deferred to Phase 4. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update Python plugin logger fallback print statements to use the standard timestamp format for consistency: - shared/plugin_logger.py: Add timestamp to _fallback_print() - opcua/opcua_logging.py: Add timestamps to info/warn/error/debug fallbacks Format: [YYYY-MM-DD HH:MM:SS] [LEVEL] [PREFIX] message Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move diagnostic and verbose logging from INFO to DEBUG level: - opcua_security.py: Certificate details, security setup debug blocks - user_manager.py: Per-connection authentication details - address_space.py: Node creation details - server.py: Endpoint verification, setup progress - plugin.py: Internal initialization steps - callbacks.py: Permission callback registration details - synchronization.py: Sync manager internal state - config.py: Configuration parsing details - opcua_memory.py: Metadata caching details Keep as INFO: Important status messages (server started/stopped, plugin initialized, security initialized, sync loop status) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Normalize log output format for human-readable stdout
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.
This pull request refactors the plugin driver codebase to use a unified logging system (
log_info,log_debug,log_error,log_warn) instead of directprintf/fprintf/putsstatements for status and error messages. This improves consistency, makes log levels explicit, and centralizes output formatting and control.Logging system integration:
printf,fprintf, and similar direct output calls with the appropriate logging macros (log_info,log_debug,log_error,log_warn) throughoutplugin_driver.candplugin_config.cfor status, debug, warning, and error messages. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25]Codebase maintenance:
#include "../plc_app/utils/log.h"toplugin_config.cto enable use of the logging macros.This change centralizes and standardizes logging, making it easier to control log output and maintain the codebase.