mavsdk_tests: add timestamp to log output

The timestamp is added when the output is queued up, rather than later
when the queue is emptied and some time might have passed.
This commit is contained in:
Julian Oes
2022-01-06 09:24:32 -05:00
committed by Daniel Agar
parent dd6fb58f82
commit 2d8ebc6839
2 changed files with 8 additions and 7 deletions
+8
View File
@@ -74,10 +74,18 @@ class Runner:
break
if not line or line == "\n":
continue
line = self.add_prefix(10, self.name, line)
self.output_queue.put(line)
self.log_fd.write(line)
self.log_fd.flush()
def add_prefix(self, width: int, name: str, text: str) -> str:
return "[" + self.seconds() + "|" + name.ljust(width) + "] " + text
def seconds(self) -> str:
dt = time.time() - self.start_time
return "{: 8.03f}".format(dt)
def poll(self) -> Optional[int]:
return self.process.poll()