diff options
author | Carlos Chinchilla <cachinchilla@google.com> | 2022-03-24 15:00:02 -0700 |
---|---|---|
committer | CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-03-25 21:57:55 +0000 |
commit | 5c95ca3998e63248eb7d1c218844362bb5be9d99 (patch) | |
tree | 5d1e7693545ad2f57d088b648d5d88b12d4efa3f | |
parent | b9961bc228aa72fa3df68fd0e8865221302db111 (diff) | |
download | pigweed-5c95ca3998e63248eb7d1c218844362bb5be9d99.tar.gz |
pw_system: Log log drop reason when available
Change-Id: I91fd3f9beb6e747ff0383aff8e4c61dffe557e4a
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/89041
Reviewed-by: Keir Mierle <keir@google.com>
Reviewed-by: Armando Montanez <amontanez@google.com>
Pigweed-Auto-Submit: Carlos Chinchilla <cachinchilla@google.com>
Commit-Queue: Carlos Chinchilla <cachinchilla@google.com>
-rw-r--r-- | pw_system/py/pw_system/device.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/pw_system/py/pw_system/device.py b/pw_system/py/pw_system/device.py index b99db21b4..1288f68b8 100644 --- a/pw_system/py/pw_system/device.py +++ b/pw_system/py/pw_system/device.py @@ -100,10 +100,9 @@ class Device: if error != Status.CANCELLED: self.listen_to_log_stream() - def _handle_log_drop_count(self, drop_count: int): - message = f'Dropped {drop_count} log' - if drop_count > 1: - message += 's' + def _handle_log_drop_count(self, drop_count: int, reason: str): + log_text = 'log' if drop_count == 1 else 'logs' + message = f'Dropped {drop_count} {log_text} due to {reason}' self._emit_device_log(logging.WARNING, '', '', '', message) def _check_for_dropped_logs(self, log_entries_proto: log_pb2.LogEntries): @@ -115,7 +114,7 @@ class Device: self._expected_log_sequence_id = ( log_entries_proto.first_entry_sequence_id + messages_received) if dropped_log_count > 0: - self._handle_log_drop_count(dropped_log_count) + self._handle_log_drop_count(dropped_log_count, 'loss at transport') elif dropped_log_count < 0: _LOG.error('Log sequence ID is smaller than expected') @@ -135,8 +134,10 @@ class Device: # Handle dropped count. if log_proto.dropped: - self._handle_log_drop_count(log_proto.dropped) - return + drop_reason = log_proto.message.decode("utf-8").lower( + ) if log_proto.message else 'enqueue failure on device' + self._handle_log_drop_count(log_proto.dropped, drop_reason) + continue self._emit_device_log(level, '', decoded_timestamp, log.module, log.message, **dict(log.fields)) |