Skip to content

Commit

Permalink
RichHandler add omit_repeated_times parameter (#62)
Browse files Browse the repository at this point in the history
* RichHandler add omit_repeated_times parameter

* More

* Update min requirements

---------

Co-authored-by: Sorin Sbarnea <sorin.sbarnea@gmail.com>
Co-authored-by: Sorin Sbarnea <ssbarnea@redhat.com>
  • Loading branch information
3 people authored Jun 14, 2024
1 parent 579a73b commit 07a8dab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
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

0 comments on commit 07a8dab

Please sign in to comment.