diff --git a/redbot/core/_cli.py b/redbot/core/_cli.py index 333e78fe7..e1fbd9819 100644 --- a/redbot/core/_cli.py +++ b/redbot/core/_cli.py @@ -314,6 +314,19 @@ def parse_cli_flags(args): default=None, help="Forcefully disables the Rich logging handlers.", ) + # DEP-WARN: use argparse.BooleanOptionalAction when we drop support for Python 3.8 + parser.add_argument( + "--rich-tracebacks", + action="store_true", + default=False, + help="Format the Python exception tracebacks using Rich (with syntax highlighting)." + " *May* be useful to increase traceback readability during development.", + ) + parser.add_argument( + "--no-rich-tracebacks", + action="store_false", + dest="rich_tracebacks", + ) parser.add_argument( "--rich-traceback-extra-lines", type=non_negative_int, diff --git a/redbot/logging.py b/redbot/logging.py index 0e21793e5..540a132c5 100644 --- a/redbot/logging.py +++ b/redbot/logging.py @@ -1,4 +1,5 @@ import argparse +import logging import logging.handlers import pathlib import re @@ -33,6 +34,7 @@ from rich.traceback import PathHighlighter, Traceback # DEP-WARN MAX_OLD_LOGS = 8 +log = logging.getLogger("red.logging") class RotatingFileHandler(logging.handlers.RotatingFileHandler): @@ -322,7 +324,7 @@ def init_logging(level: int, location: pathlib.Path, cli_flags: argparse.Namespa rich_formatter = logging.Formatter("{message}", datefmt="[%X]", style="{") stdout_handler = RedRichHandler( - rich_tracebacks=True, + rich_tracebacks=cli_flags.rich_tracebacks, show_path=False, highlighter=NullHighlighter(), tracebacks_extra_lines=cli_flags.rich_traceback_extra_lines, @@ -379,3 +381,9 @@ def init_logging(level: int, location: pathlib.Path, cli_flags: argparse.Namespa for fhandler in (latest_fhandler, all_fhandler): fhandler.setFormatter(file_formatter) root_logger.addHandler(fhandler) + + if not enable_rich_logging and cli_flags.rich_tracebacks: + log.warning( + "Rich tracebacks were requested but they will not be enabled" + " as Rich logging is not active." + )