diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9a734a9..da7c82a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -51,9 +51,9 @@ repos: additional_dependencies: - click-help-colors - click-option-group + - enrich - packaging - pygithub - - rich - repo: https://github.com/pre-commit/mirrors-pylint rev: v2.6.0 hooks: diff --git a/lib/gri/__main__.py b/lib/gri/__main__.py index 018656b..be5ecb2 100755 --- a/lib/gri/__main__.py +++ b/lib/gri/__main__.py @@ -11,7 +11,6 @@ from click_help_colors import HelpColorsGroup from requests.exceptions import HTTPError from rich import box -from rich.logging import RichHandler from rich.markdown import Markdown from rich.table import Table @@ -39,12 +38,9 @@ def command_line_wrapper(func): @wraps(func) def inner_func(*args, **kwargs): # before - handler = RichHandler(show_time=False, show_path=False) - LOG.addHandler(handler) - ctx = args[0] LOG.setLevel(get_logging_level(ctx)) - LOG.info("Called with %s", ctx.params) + LOG.debug("Called with %s", ctx.params) if " " in ctx.params["user"]: ctx.params["user"] = f"\"{ctx.params['user']}\"" diff --git a/lib/gri/console.py b/lib/gri/console.py index 8cb002a..0edc880 100644 --- a/lib/gri/console.py +++ b/lib/gri/console.py @@ -1,7 +1,10 @@ import logging +import sys import rich -from rich.console import Console, ConsoleOptions, RenderResult +from enrich.console import Console +from enrich.logging import RichHandler +from rich.console import ConsoleOptions, RenderResult from rich.markdown import CodeBlock, Markdown from rich.syntax import Syntax from rich.terminal_theme import TerminalTheme @@ -46,8 +49,26 @@ def bootstrap() -> Console: Markdown.elements["code_block"] = MyCodeBlock + + # We also initialize the logging console + logging_console = Console(file=sys.stderr, force_terminal=1, theme=theme) + + logger = logging.getLogger() # type: logging.Logger + # logger.setLevel(logging.DEBUG) + + handler = RichHandler( + console=logging_console, show_time=False, show_path=False, markup=True + ) # type: ignore + # logger.addHandler(handler) + logger.handlers = [handler] + logger.propagate = False + return Console( - theme=theme, highlighter=rich.highlighter.ReprHighlighter(), record=True + theme=theme, + highlighter=rich.highlighter.ReprHighlighter(), + record=True, + soft_wrap=True, + redirect=True, ) @@ -83,7 +104,7 @@ def get_logging_level(ctx) -> int: class MyCodeBlock(CodeBlock): # pylint: disable=unused-argument def __rich_console__( - self, console: Console, options: ConsoleOptions + self, console: rich.console.Console, options: ConsoleOptions ) -> RenderResult: code = str(self.text).rstrip() syntax = Syntax(code, self.lexer_name, theme=self.theme) diff --git a/setup.cfg b/setup.cfg index 54f59d7..52af0b1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -56,13 +56,13 @@ setup_requires = # These are required in actual runtime: install_requires = - click>=7.1.2 click-help-colors>=0.6 + click>=7.1.2 dataclasses; python_version<"3.7" + enrich>=1.2.1 pygithub pyyaml>=5.3.1 requests - rich>=6.2.0 [options.entry_points] console_scripts =