From 06206eb661a1491748335077fc03681fb133a412 Mon Sep 17 00:00:00 2001 From: Nathan Page Date: Sun, 26 Jul 2020 15:32:45 -0400 Subject: [PATCH 1/5] feat: match Console and RichHandler configuration flags with LogRender --- rich/console.py | 4 +++- rich/logging.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/rich/console.py b/rich/console.py index ee5870b8..2bffb0c7 100644 --- a/rich/console.py +++ b/rich/console.py @@ -296,6 +296,7 @@ class Console: emoji (bool, optional): Enable emoji code. Defaults to True. highlight (bool, optional): Enable automatic highlighting. Defaults to True. log_time (bool, optional): Boolean to enable logging of time by :meth:`log` methods. Defaults to True. + log_level (bool, optional): Boolean to enable logging of level by :meth:`log` methods. Defaults to True. log_path (bool, optional): Boolean to enable the logging of the caller by :meth:`log`. Defaults to True. log_time_format (str, optional): Log time format if ``log_time`` is enabled. Defaults to "[%X] ". highlighter (HighlighterType, optional): Default highlighter. @@ -321,6 +322,7 @@ class Console: emoji: bool = True, highlight: bool = True, log_time: bool = True, + log_level: bool = True, log_path: bool = True, log_time_format: str = "[%X]", highlighter: Optional["HighlighterType"] = ReprHighlighter(), @@ -362,7 +364,7 @@ class Console: self._lock = threading.RLock() self._log_render = LogRender( - show_time=log_time, show_path=log_path, time_format=log_time_format + show_time=log_time, show_level=log_level, show_path=log_path, time_format=log_time_format ) self.highlighter: HighlighterType = highlighter or _null_highlighter self.safe_box = safe_box diff --git a/rich/logging.py b/rich/logging.py index f7f27791..ccfadb04 100644 --- a/rich/logging.py +++ b/rich/logging.py @@ -48,6 +48,8 @@ class RichHandler(Handler): level: int = logging.NOTSET, console: Console = None, *, + show_time: bool = True, + show_level: bool = True, show_path: bool = True, enable_link_path: bool = True, highlighter: Highlighter = None, @@ -56,7 +58,7 @@ class RichHandler(Handler): super().__init__(level=level) self.console = console or get_console() self.highlighter = highlighter or self.HIGHLIGHTER_CLASS() - self._log_render = LogRender(show_level=True, show_path=show_path) + self._log_render = LogRender(show_time=show_time, show_level=show_level, show_path=show_path) self.enable_link_path = enable_link_path self.markup = markup From 7ac6678dbcab8df218a700fd97b65f52108c941b Mon Sep 17 00:00:00 2001 From: Nathan Page Date: Sun, 26 Jul 2020 15:36:06 -0400 Subject: [PATCH 2/5] format: use black to format changed files --- rich/console.py | 5 ++++- rich/logging.py | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/rich/console.py b/rich/console.py index 2bffb0c7..b92738ec 100644 --- a/rich/console.py +++ b/rich/console.py @@ -364,7 +364,10 @@ class Console: self._lock = threading.RLock() self._log_render = LogRender( - show_time=log_time, show_level=log_level, show_path=log_path, time_format=log_time_format + show_time=log_time, + show_level=log_level, + show_path=log_path, + time_format=log_time_format, ) self.highlighter: HighlighterType = highlighter or _null_highlighter self.safe_box = safe_box diff --git a/rich/logging.py b/rich/logging.py index ccfadb04..ed88e2f0 100644 --- a/rich/logging.py +++ b/rich/logging.py @@ -58,7 +58,9 @@ class RichHandler(Handler): super().__init__(level=level) self.console = console or get_console() self.highlighter = highlighter or self.HIGHLIGHTER_CLASS() - self._log_render = LogRender(show_time=show_time, show_level=show_level, show_path=show_path) + self._log_render = LogRender( + show_time=show_time, show_level=show_level, show_path=show_path + ) self.enable_link_path = enable_link_path self.markup = markup From c5d8d38f08ec579d7fb60e68d0e905d06c83f95f Mon Sep 17 00:00:00 2001 From: Nathan Page Date: Mon, 27 Jul 2020 12:06:58 -0400 Subject: [PATCH 3/5] fix: console default hides log level --- rich/console.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rich/console.py b/rich/console.py index b92738ec..958da37d 100644 --- a/rich/console.py +++ b/rich/console.py @@ -296,7 +296,7 @@ class Console: emoji (bool, optional): Enable emoji code. Defaults to True. highlight (bool, optional): Enable automatic highlighting. Defaults to True. log_time (bool, optional): Boolean to enable logging of time by :meth:`log` methods. Defaults to True. - log_level (bool, optional): Boolean to enable logging of level by :meth:`log` methods. Defaults to True. + log_level (bool, optional): Boolean to enable logging of level by :meth:`log` methods. Defaults to False. log_path (bool, optional): Boolean to enable the logging of the caller by :meth:`log`. Defaults to True. log_time_format (str, optional): Log time format if ``log_time`` is enabled. Defaults to "[%X] ". highlighter (HighlighterType, optional): Default highlighter. @@ -322,7 +322,7 @@ class Console: emoji: bool = True, highlight: bool = True, log_time: bool = True, - log_level: bool = True, + log_level: bool = False, log_path: bool = True, log_time_format: str = "[%X]", highlighter: Optional["HighlighterType"] = ReprHighlighter(), From 6a9f04e5020db3486f18cc14a11001a0d0cb157f Mon Sep 17 00:00:00 2001 From: Nathan Page Date: Mon, 27 Jul 2020 12:20:57 -0400 Subject: [PATCH 4/5] fix: remove log levels as console has no meaning of a log_level --- rich/console.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/rich/console.py b/rich/console.py index 958da37d..5456cbdd 100644 --- a/rich/console.py +++ b/rich/console.py @@ -296,7 +296,6 @@ class Console: emoji (bool, optional): Enable emoji code. Defaults to True. highlight (bool, optional): Enable automatic highlighting. Defaults to True. log_time (bool, optional): Boolean to enable logging of time by :meth:`log` methods. Defaults to True. - log_level (bool, optional): Boolean to enable logging of level by :meth:`log` methods. Defaults to False. log_path (bool, optional): Boolean to enable the logging of the caller by :meth:`log`. Defaults to True. log_time_format (str, optional): Log time format if ``log_time`` is enabled. Defaults to "[%X] ". highlighter (HighlighterType, optional): Default highlighter. @@ -322,7 +321,6 @@ class Console: emoji: bool = True, highlight: bool = True, log_time: bool = True, - log_level: bool = False, log_path: bool = True, log_time_format: str = "[%X]", highlighter: Optional["HighlighterType"] = ReprHighlighter(), @@ -365,7 +363,6 @@ class Console: self._lock = threading.RLock() self._log_render = LogRender( show_time=log_time, - show_level=log_level, show_path=log_path, time_format=log_time_format, ) From 3e746dcc0bb9cbfb55945ad622ff85966816136e Mon Sep 17 00:00:00 2001 From: Nathan Page Date: Mon, 27 Jul 2020 12:25:47 -0400 Subject: [PATCH 5/5] format: format console file --- rich/console.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rich/console.py b/rich/console.py index 5456cbdd..d6196de5 100644 --- a/rich/console.py +++ b/rich/console.py @@ -362,9 +362,7 @@ class Console: self._lock = threading.RLock() self._log_render = LogRender( - show_time=log_time, - show_path=log_path, - time_format=log_time_format, + show_time=log_time, show_path=log_path, time_format=log_time_format, ) self.highlighter: HighlighterType = highlighter or _null_highlighter self.safe_box = safe_box