def basicConfig(self, log_file_name=None, maxBytes=1E7, backupCount=5, with_gui_exc_handler=True): # prepare exception handler to report exceptions as error log messages # and to taurus message box (if with_gui is set) hook_to = None if with_gui_exc_handler: import taurus.qt.qtgui.dialog hook_to = taurus.qt.qtgui.dialog.TaurusExceptHookMessageBox() sys.excepthook = LogExceptHook(hook_to=hook_to) # create a file log handler try: if log_file_name is None: log_file_name = self.__buildLogFileName() f_h = logging.handlers.RotatingFileHandler(log_file_name, maxBytes=maxBytes, backupCount=backupCount) Logger.addRootLogHandler(f_h) if self._out is not None: self._out.std = sys.__stdout__ self._out.addLogHandler(f_h) if self._out is not None: self._err.std = sys.__stderr__ self._err.addLogHandler(f_h) self.info("Logs will be saved in %s", log_file_name) except: self.warning("'%s' could not be created. Logs will not be stored", log_file_name) self.debug("Error description", exc_info=1)
def report(self, *exc_info): app = Qt.QApplication.instance() if app is None: import taurus.core.util LogExceptHook().report(*exc_info) return msgbox = self._getMessageBox(*exc_info) if msgbox is None: return if self._title is not None: msgbox.setWindowTitle(self._title) if self._msg is not None: msgbox.setText(self._msg) msgbox.exec_()