def setup_panes(self, action=None): assert not self.managed_panes or (self.managed_panes and self.logstream) assert action is not None # TODO: managed_panes and echo are incompatible if self.managed_panes: self.pane_manager = PaneManager(self) shutit_threads.track_main_thread() else: if action == 'build': shutit_threads.track_main_thread_simple()
def setup_logging(self): assert not self.managed_panes or (self.managed_panes and self.logstream) assert self.logfile is not None if self.pane_manager is not None: # TODO: remove this? return # TODO: managed_panes and echo are incompatible if self.managed_panes: self.nocolor = True self.pane_manager = PaneManager(self) shutit_threads.track_main_thread() else: shutit_threads.track_main_thread_simple() logformat = '%(asctime)s %(levelname)s: %(message)s' logobj = logging.getLogger(self.logger_name) if self.managed_panes: # Set up logging for https://stackoverflow.com/questions/31999627/storing-logger-messages-in-a-string self.loglevel = self.loglevel.upper() if self.loglevel == 'DEBUG': logging.basicConfig(format=logformat, stream=self.logstream) logobj.level = logging.DEBUG elif self.loglevel == 'ERROR': logging.basicConfig(format=logformat, stream=self.logstream) logobj.level = logging.ERROR elif self.loglevel in ('WARN', 'WARNING'): logging.basicConfig(format=logformat, stream=self.logstream) logobj.level = logging.WARNING elif self.loglevel == 'CRITICAL': logging.basicConfig(format=logformat, stream=self.logstream) logobj.level = logging.CRITICAL elif self.loglevel == 'INFO': logging.basicConfig(format=logformat, stream=self.logstream) logobj.level = logging.INFO else: logging.basicConfig(format=logformat, stream=self.logstream) logobj.level = logging.DEBUG elif self.logfile == '': self.loglevel = self.loglevel.upper() if self.loglevel == 'DEBUG': logging.basicConfig(format=logformat) logobj.level = logging.DEBUG elif self.loglevel == 'ERROR': logging.basicConfig(format=logformat) logobj.level = logging.ERROR elif self.loglevel in ('WARN', 'WARNING'): logging.basicConfig(format=logformat) logobj.level = logging.WARNING elif self.loglevel == 'CRITICAL': logging.basicConfig(format=logformat) logobj.level = logging.CRITICAL elif self.loglevel == 'INFO': logging.basicConfig(format=logformat) logobj.level = logging.INFO else: logging.basicConfig(format=logformat) logobj.level = logging.DEBUG else: self.loglevel = self.loglevel.upper() if self.loglevel == 'DEBUG': logging.basicConfig(format=logformat, filename=self.logfile) logobj.level = logging.DEBUG elif self.loglevel == 'ERROR': logging.basicConfig(format=logformat, filename=self.logfile) logobj.level = logging.ERROR elif self.loglevel in ('WARN', 'WARNING'): logging.basicConfig(format=logformat, filename=self.logfile) logobj.level = logging.WARNING elif self.loglevel == 'CRITICAL': logging.basicConfig(format=logformat, filename=self.logfile) logobj.level = logging.CRITICAL elif self.loglevel == 'INFO': logging.basicConfig(format=logformat, filename=self.logfile) logobj.level = logging.INFO else: logging.basicConfig(format=logformat, filename=self.logfile) logobj.level = logging.DEBUG self.loglevel = logobj.getEffectiveLevel() if self.loglevel <= logging.INFO: self.log_trace_when_idle = True else: self.log_trace_when_idle = False