-
-
Notifications
You must be signed in to change notification settings - Fork 261
Open
Description
Summary
Enhance logging with structured context (PLC address, operation type, area, DB number) for better observability in multi-PLC environments.
Background
The library currently uses standard Python logging. In production environments with multiple PLC connections, it can be hard to correlate log messages to specific PLCs or operations. Structured logging would make filtering and analysis much easier.
What needs to be done
- Add structured context to log messages (PLC IP, rack/slot, operation, area, DB number, offset, size)
- Use
logging.LoggerAdapteror similar pattern to inject context automatically - Make it optional and backward-compatible (standard logging still works)
- Consider compatibility with structured logging libraries (structlog, python-json-logger)
- Add connection ID for tracking specific sessions
- Log operation timing (duration of reads/writes) at DEBUG level
- Add documentation on logging configuration
Example
import logging
import snap7
# Standard logging still works
logging.basicConfig(level=logging.DEBUG)
client = snap7.Client()
client.connect("192.168.1.10", 0, 1)
client.db_read(1, 0, 4)
# DEBUG snap7.client [192.168.1.10:0/1] db_read db=1 offset=0 size=4 duration=12msNotes
- Should not add any new dependencies — use stdlib logging
- Structured logging library integration should be possible but not required
- Performance overhead of logging should be minimal (lazy formatting)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels