mirror of
https://github.com/aclist/dztui.git
synced 2026-08-26 17:57:06 +02:00
feat: LogManager
This commit is contained in:
parent
106b201804
commit
978daa7a28
27
dzgui/managers/log.py
Normal file
27
dzgui/managers/log.py
Normal file
@ -0,0 +1,27 @@
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from dzgui.util.strings import delimiter
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class LogManager:
|
||||
def __init__(self) -> None:
|
||||
self.CRITICAL = "CRITICAL"
|
||||
self.WARNING = "WARNING"
|
||||
|
||||
# TODO: more of a static method
|
||||
def get_alerts(self, log_path: Path) -> tuple[int]:
|
||||
try:
|
||||
with open(log_path, "r") as f:
|
||||
lines = f.read().splitlines()
|
||||
errors = [
|
||||
line for line in lines if line.split(delimiter)[1] == self.CRITICAL
|
||||
]
|
||||
warnings = [
|
||||
line for line in lines if line.split(delimiter)[1] == self.WARNING
|
||||
]
|
||||
return len(warnings), len(errors)
|
||||
except Exception as e:
|
||||
logger.critical(e)
|
||||
return 0, 0
|
||||
Loading…
Reference in New Issue
Block a user