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
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=12ms
Notes
- 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)
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
logging.LoggerAdapteror similar pattern to inject context automaticallyExample
Notes