[#136] Added exclude_filter

Added exclude_filter

Signed-off-by: Mikhail Kadilov <m.kadilov@yadro.com>
This commit is contained in:
Mikhail Kadilov 2023-12-01 15:54:28 +03:00 committed by Andrey Berezin
parent dc6b0e407f
commit 17c1a4f14b
2 changed files with 6 additions and 0 deletions

View file

@ -235,6 +235,7 @@ class DockerHost(Host):
since: Optional[datetime] = None, since: Optional[datetime] = None,
until: Optional[datetime] = None, until: Optional[datetime] = None,
unit: Optional[str] = None, unit: Optional[str] = None,
exclude_filter: Optional[str] = None,
) -> str: ) -> str:
client = self._get_docker_client() client = self._get_docker_client()
filtered_logs = "" filtered_logs = ""
@ -248,6 +249,10 @@ class DockerHost(Host):
matches = re.findall(filter_regex, filtered_logs, re.IGNORECASE + re.MULTILINE) matches = re.findall(filter_regex, filtered_logs, re.IGNORECASE + re.MULTILINE)
found = list(matches) found = list(matches)
if exclude_filter:
found = [match for match in found if match != exclude_filter]
if found: if found:
filtered_logs += f"{container_name}:\n{os.linesep.join(found)}" filtered_logs += f"{container_name}:\n{os.linesep.join(found)}"

View file

@ -287,6 +287,7 @@ class Host(ABC):
since: Optional[datetime] = None, since: Optional[datetime] = None,
until: Optional[datetime] = None, until: Optional[datetime] = None,
unit: Optional[str] = None, unit: Optional[str] = None,
exclude_filter: Optional[str] = None,
) -> str: ) -> str:
"""Get logs from host filtered by regex. """Get logs from host filtered by regex.