Labsmore / pyuscope

Python machine vision platform
BSD 2-Clause "Simplified" License
80 stars 17 forks source link

Log messages displayed prior to the main window's creation are silently dropped #426

Open philpem opened 9 months ago

philpem commented 9 months ago

This seems to be a quirk of the log() function in ArgusCommon.

The "Joystick not found" message doesn't appear in any of the log lines -- nor do any of the log lines I'm printing out with ArgusCommon.log() while things (imager pipeline, preview window) are initialising.

I think the issue is that while the GUI is initialising, self.logs in ArgusCommon starts out empty, and everything further down the tree uses it for logging (via ArgusCommon.log()). The first logger isn't added to .logs until part-way through MainWindow.init runs. Any log message output before that point will be silently dropped.

The following patch resolves this by outputting such messages to stdout:

diff --git a/uscope/gui/common.py b/uscope/gui/common.py
index 1c3620d..f730d4f 100644
--- a/uscope/gui/common.py
+++ b/uscope/gui/common.py
@@ -414,6 +414,11 @@ class ArgusCommon(QObject):
         WARNING: this is not thread safe
         If you need something thread safe use microscope.log
         """
+        if len(self.logs) == 0:
+            if not newline:
+                print("LOG:", s, end="")
+            else:
+                print("LOG:", s)
         for log in self.logs:
             log(s, newline=newline)

This isn't perfect - it could be argued that it'd be better to store the (s, newline) pairs when self.logs is empty, then print them on the first log() call after self.logs has at least one log function defined.

As things are, there's only one log function - it's in the main window class, and it logs to the main window and data/log.txt.