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 run_macro(self, par_str_list, asynch=False): if isinstance(par_str_list, (str, unicode)): par_str_list = par_str_list, if not hasattr(self, "Output"): import sys import logging Logger.addLevelName(15, "OUTPUT") def output(loggable, msg, *args, **kw): loggable.getLogObj().log(Logger.Output, msg, *args, **kw) Logger.output = output Logger.disableLogOutput() Logger.setLogLevel(Logger.Output) #filter = taurus.core.util.LogFilter(level=Logger.Output) formatter = logging.Formatter(fmt="%(message)s") Logger.setLogFormat("%(message)s") handler = logging.StreamHandler(stream=sys.stdout) #handler.addFilter(filter) Logger.addRootLogHandler(handler) #handler.setFormatter(formatter) #logger.addHandler(handler) #logger.addFilter(filter) self.__logging_info = handler, filter, formatter # result of a macro #Logger.addLevelName(18, "RESULT") return self.macro_executor.run(par_str_list, asynch=asynch)
def __init__(self, capacity=500000, freq=0.25): super(Qt.QAbstractTableModel, self).__init__() logging.Handler.__init__(self) self._capacity = capacity self._records = [] self._accumulated_records = [] Logger.addRootLogHandler(self) self.startTimer(freq * 1000)