mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-05 18:58:53 -05:00
Disable Rich tracebacks by default (#6576)
This commit is contained in:
parent
b177c80b4e
commit
2dbbb51208
@ -314,6 +314,19 @@ def parse_cli_flags(args):
|
|||||||
default=None,
|
default=None,
|
||||||
help="Forcefully disables the Rich logging handlers.",
|
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(
|
parser.add_argument(
|
||||||
"--rich-traceback-extra-lines",
|
"--rich-traceback-extra-lines",
|
||||||
type=non_negative_int,
|
type=non_negative_int,
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import argparse
|
import argparse
|
||||||
|
import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
import pathlib
|
import pathlib
|
||||||
import re
|
import re
|
||||||
@ -33,6 +34,7 @@ from rich.traceback import PathHighlighter, Traceback # DEP-WARN
|
|||||||
|
|
||||||
|
|
||||||
MAX_OLD_LOGS = 8
|
MAX_OLD_LOGS = 8
|
||||||
|
log = logging.getLogger("red.logging")
|
||||||
|
|
||||||
|
|
||||||
class RotatingFileHandler(logging.handlers.RotatingFileHandler):
|
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="{")
|
rich_formatter = logging.Formatter("{message}", datefmt="[%X]", style="{")
|
||||||
|
|
||||||
stdout_handler = RedRichHandler(
|
stdout_handler = RedRichHandler(
|
||||||
rich_tracebacks=True,
|
rich_tracebacks=cli_flags.rich_tracebacks,
|
||||||
show_path=False,
|
show_path=False,
|
||||||
highlighter=NullHighlighter(),
|
highlighter=NullHighlighter(),
|
||||||
tracebacks_extra_lines=cli_flags.rich_traceback_extra_lines,
|
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):
|
for fhandler in (latest_fhandler, all_fhandler):
|
||||||
fhandler.setFormatter(file_formatter)
|
fhandler.setFormatter(file_formatter)
|
||||||
root_logger.addHandler(fhandler)
|
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."
|
||||||
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user