diff --git a/addons/hw_drivers/controllers/driver.py b/addons/hw_drivers/controllers/driver.py index fc61c8ed63ee0..64fad0bdf50d1 100755 --- a/addons/hw_drivers/controllers/driver.py +++ b/addons/hw_drivers/controllers/driver.py @@ -10,6 +10,7 @@ import urllib3 import os import socket +import sys from importlib import util import v4l2 from fcntl import ioctl @@ -97,6 +98,27 @@ def connect_box(self, token): with open(image, 'rb') as f: return f.read() +#---------------------------------------------------------- +# Log Exceptions +#---------------------------------------------------------- + +class ExceptionLogger: + """ + Redirect Exceptions to the logger to keep track of them in the log file. + """ + + def __init__(self): + self.logger = logging.getLogger() + + def write(self, message): + if message != '\n': + self.logger.err(message) + + def flush(self): + pass + +sys.stderr = ExceptionLogger() + #---------------------------------------------------------- # Drivers #----------------------------------------------------------