def pexcept(self, msg: Any, *, end: str = '\n', apply_style: bool = True) -> None: """Print Exception message to sys.stderr. If debug is true, print exception traceback if one exists. :param msg: message or Exception to print :param end: string appended after the end of the message, default a newline :param apply_style: If True, then ansi.style_error will be applied to the message text. Set to False in cases where the message text already has the desired style. Defaults to True. """ if self.debug and sys.exc_info() != (None, None, None): import traceback traceback.print_exc() if isinstance(msg, Exception): final_msg = f"EXCEPTION of type '{type(msg).__name__}' occurred with message: {msg}" else: final_msg = str(msg) if apply_style: final_msg = ansi.style_error(final_msg) if not self.debug and 'debug' in self.settables: warning = "\n [!] To enable full traceback, run the following command: 'setg debug true'" final_msg += ansi.style_warning(warning) self.perror(final_msg, end=end, apply_style=False)
def emit(self, record: logging.LogRecord): output = self.format(record) if record.levelno >= logging.ERROR: self.__shell.poutput(ansi.style_error(output)) elif record.levelno >= logging.WARN: self.__shell.poutput(ansi.style_warning(output)) else: self.__shell.pfeedback(ansi.style_success(output))
def emit(self, record: logging.LogRecord): output = self.format(record) if record.levelno >= logging.ERROR: print(ansi.style_error(output)) elif record.levelno >= logging.WARN: print(ansi.style_warning(output)) else: print(ansi.style_success(output))
def perror(self, msg: str = '', *, end: str = '\n', apply_style: bool = True) -> None: if apply_style: final_msg = ansi.style_error(msg) else: final_msg = "{}".format(msg) ansi.style_aware_write(sys.stderr, final_msg + end)
def perror(self, msg: Any = '', *, end: str = '\n', apply_style: bool = True) -> None: if apply_style: final_msg = ansi.style_error(msg) else: final_msg = str(msg) ansi.style_aware_write(self.stdout, final_msg + end)