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
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ classifiers = [
"Topic :: Utilities",
]
keywords = ["console", "logging", "rich"]
dependencies = ["rich >= 9.5.1, < 12.5.0"]
dependencies = ["rich >= 10.0.0, < 12.5.0"]

[project.urls]
homepage = "https://github.com/pycontribs/enrich"
Expand Down
6 changes: 5 additions & 1 deletion src/enrich/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@
class FluidLogRender: # pylint: disable=too-few-public-methods
"""Renders log by not using columns and avoiding any wrapping."""

# pylint: disable=too-many-arguments
def __init__(
self,
show_time: bool = False,
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 +46,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 +85,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