Log port list once, then only log changes#1339
Conversation
Replace repeated "Available connection ports are:" dumps on every 3-second refresh with a diff-based approach: the full port list is logged once on first discovery; subsequent discoveries only log "Connection port added:" or "Connection port removed:" lines when the list actually changes, and are silent otherwise.
There was a problem hiding this comment.
Pull request overview
This PR reduces log noise during periodic connection port discovery by logging the full port list only once per FlightControllerConnection instance, and subsequently logging only added/removed ports when the discovered set changes.
Changes:
- Track the last logged set of discovered connection tuples.
- Replace repeated full port dumps with
_log_connection_changes()that logs only diffs after the first discovery.
| def _log_connection_changes(self) -> None: | ||
| """Log port list on first discovery; log only added/removed ports on subsequent discoveries.""" | ||
| current = self._connection_tuples | ||
| previous = self._logged_connection_tuples | ||
|
|
||
| if previous is None: | ||
| # First discovery - log everything | ||
| logging_info(_("Available connection ports are:")) | ||
| for port in current: | ||
| logging_info("%s - %s", port[0], port[1]) | ||
| else: | ||
| current_set = set(current) | ||
| previous_set = set(previous) | ||
| for port in sorted(current_set - previous_set): | ||
| logging_info(_("Connection port added: %s - %s"), port[0], port[1]) | ||
| for port in sorted(previous_set - current_set): | ||
| logging_info(_("Connection port removed: %s - %s"), port[0], port[1]) | ||
|
|
||
| self._logged_connection_tuples = list(current) |
There was a problem hiding this comment.
The new diff-based logging behavior in _log_connection_changes isn’t covered by tests. Since this repo already uses pytest for FlightControllerConnection, please add a test that captures logs (e.g., via caplog) to assert: (1) first discover_connections() logs the full list once, (2) a second call with the same ports produces no new port-list logs, and (3) adding/removing a port results in exactly the expected "added"/"removed" log lines.
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
Replace repeated "Available connection ports are:" dumps on every 3-second refresh with a diff-based approach: the full port list is logged once on first discovery; subsequent discoveries only log "Connection port added:" or "Connection port removed:" lines when the list actually changes, and are silent otherwise.