Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RichHandler add omit_repeated_times parameter #62

Merged
merged 4 commits into from
Jun 14, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/enrich/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ def __init__(
show_level: bool = False,
show_path: bool = True,
time_format: str = "[%x %X]",
omit_repeated_times: bool = True,
) -> None:
self.show_time = show_time
self.show_level = show_level
self.show_path = show_path
self.time_format = time_format
self.omit_repeated_times = omit_repeated_times
self._last_time: Optional[str] = None

def __call__( # pylint: disable=too-many-arguments
Expand All @@ -43,7 +45,7 @@ def __call__( # pylint: disable=too-many-arguments
if log_time is None:
log_time = datetime.now()
log_time_display = log_time.strftime(time_format or self.time_format) + " "
if log_time_display == self._last_time:
if self.omit_repeated_times and log_time_display == self._last_time:
result += Text(" " * len(log_time_display))
else:
result += Text(log_time_display)
Expand Down Expand Up @@ -82,4 +84,5 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
show_time=kwargs.get("show_time", False),
show_level=kwargs.get("show_level", True),
show_path=kwargs.get("show_path", False),
omit_repeated_times=kwargs.get("omit_repeated_times", True),
) # type: ignore
Loading