From c4405f40f3a8e93e72e819a97e92b365dcce4a7f Mon Sep 17 00:00:00 2001 From: Frank Epperlein Date: Sat, 13 Mar 2021 13:39:33 +0100 Subject: [PATCH 1/2] add option to not omit identical time values in log renderer --- rich/_log_render.py | 4 +++- rich/logging.py | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/rich/_log_render.py b/rich/_log_render.py index 2caad0bcc..7935c0192 100644 --- a/rich/_log_render.py +++ b/rich/_log_render.py @@ -18,12 +18,14 @@ def __init__( show_level: bool = False, show_path: bool = True, time_format: Union[str, FormatTimeCallable] = "[%x %X]", + repeat_same_time: bool = False, level_width: Optional[int] = 8, ) -> None: self.show_time = show_time self.show_level = show_level self.show_path = show_path self.time_format = time_format + self.repeat_same_time = repeat_same_time self.level_width = level_width self._last_time: Optional[Text] = None @@ -58,7 +60,7 @@ def __call__( log_time_display = time_format(log_time) else: log_time_display = Text(log_time.strftime(time_format)) - if log_time_display == self._last_time: + if log_time_display == self._last_time and not self.repeat_same_time: row.append(Text(" " * len(log_time_display))) else: row.append(log_time_display) diff --git a/rich/logging.py b/rich/logging.py index bdb8a5843..90852bc4d 100644 --- a/rich/logging.py +++ b/rich/logging.py @@ -25,6 +25,7 @@ class RichHandler(Handler): console (:class:`~rich.console.Console`, optional): Optional console instance to write logs. Default will use a global console instance writing to stdout. show_time (bool, optional): Show a column for the time. Defaults to True. + repeat_same_time (bool, optional): Do not omit repetition of the same time. Defaults to False. show_level (bool, optional): Show a column for the level. Defaults to True. show_path (bool, optional): Show the path to the original log call. Defaults to True. enable_link_path (bool, optional): Enable terminal link of path column to file. Defaults to True. @@ -60,6 +61,7 @@ def __init__( console: Console = None, *, show_time: bool = True, + repeat_same_time: bool = False, show_level: bool = True, show_path: bool = True, enable_link_path: bool = True, @@ -83,6 +85,7 @@ def __init__( show_level=show_level, show_path=show_path, time_format=log_time_format, + repeat_same_time=repeat_same_time, level_width=None, ) self.enable_link_path = enable_link_path From c235db44d518a5e4259b085cd05b44de4d1a8bee Mon Sep 17 00:00:00 2001 From: Frank Epperlein Date: Mon, 15 Mar 2021 22:38:54 +0100 Subject: [PATCH 2/2] inverse option to not omit identical time values in log renderer --- rich/_log_render.py | 6 +++--- rich/logging.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rich/_log_render.py b/rich/_log_render.py index 7935c0192..67579633a 100644 --- a/rich/_log_render.py +++ b/rich/_log_render.py @@ -18,14 +18,14 @@ def __init__( show_level: bool = False, show_path: bool = True, time_format: Union[str, FormatTimeCallable] = "[%x %X]", - repeat_same_time: bool = False, + omit_repeated_times: bool = True, level_width: Optional[int] = 8, ) -> None: self.show_time = show_time self.show_level = show_level self.show_path = show_path self.time_format = time_format - self.repeat_same_time = repeat_same_time + self.omit_repeated_times = omit_repeated_times self.level_width = level_width self._last_time: Optional[Text] = None @@ -60,7 +60,7 @@ def __call__( log_time_display = time_format(log_time) else: log_time_display = Text(log_time.strftime(time_format)) - if log_time_display == self._last_time and not self.repeat_same_time: + if log_time_display == self._last_time and self.omit_repeated_times: row.append(Text(" " * len(log_time_display))) else: row.append(log_time_display) diff --git a/rich/logging.py b/rich/logging.py index 90852bc4d..04b466003 100644 --- a/rich/logging.py +++ b/rich/logging.py @@ -25,7 +25,7 @@ class RichHandler(Handler): console (:class:`~rich.console.Console`, optional): Optional console instance to write logs. Default will use a global console instance writing to stdout. show_time (bool, optional): Show a column for the time. Defaults to True. - repeat_same_time (bool, optional): Do not omit repetition of the same time. Defaults to False. + omit_repeated_times (bool, optional): Omit repetition of the same time. Defaults to True. show_level (bool, optional): Show a column for the level. Defaults to True. show_path (bool, optional): Show the path to the original log call. Defaults to True. enable_link_path (bool, optional): Enable terminal link of path column to file. Defaults to True. @@ -61,7 +61,7 @@ def __init__( console: Console = None, *, show_time: bool = True, - repeat_same_time: bool = False, + omit_repeated_times: bool = True, show_level: bool = True, show_path: bool = True, enable_link_path: bool = True, @@ -85,7 +85,7 @@ def __init__( show_level=show_level, show_path=show_path, time_format=log_time_format, - repeat_same_time=repeat_same_time, + omit_repeated_times=omit_repeated_times, level_width=None, ) self.enable_link_path = enable_link_path