add option to not omit identical time values in log renderer

This commit is contained in:
Frank Epperlein 2021-03-13 13:39:33 +01:00
parent 6c0696a2e4
commit c4405f40f3
2 changed files with 6 additions and 1 deletions

View File

@ -18,12 +18,14 @@ class LogRender:
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 @@ class LogRender:
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)

View File

@ -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 @@ class RichHandler(Handler):
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 @@ class RichHandler(Handler):
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