diff --git a/buildhat/hat.py b/buildhat/hat.py index 395a3d6..0a277eb 100644 --- a/buildhat/hat.py +++ b/buildhat/hat.py @@ -41,6 +41,14 @@ def get(self): "description": desc} return devices + def get_logfile(self): + """Get the filename of the debug log (If enabled, None otherwise) + + :return: Path of the debug logfile + :rtype: str or None + """ + return Device._instance.debug_filename + def get_vin(self): """Get the voltage present on the input power jack diff --git a/buildhat/serinterface.py b/buildhat/serinterface.py index c8e5063..77ee53e 100644 --- a/buildhat/serinterface.py +++ b/buildhat/serinterface.py @@ -94,8 +94,10 @@ def __init__(self, firmware, signature, version, device="/dev/serial0", debug=Fa self.motorqueue = [] self.fin = False self.running = True + self.debug_filename = None if debug: tmp = tempfile.NamedTemporaryFile(suffix=".log", prefix="buildhat-", delete=False) + self.debug_filename = tmp.name logging.basicConfig(filename=tmp.name, format='%(asctime)s %(message)s', level=logging.DEBUG)