mirror of
https://github.com/aclist/dztui.git
synced 2026-10-30 14:42:54 +01:00
feat: LogManager
This commit is contained in:
1 parent
106b201804
commit
978daa7a28
1 file changed
+27
@@ -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
|
||||||
Reference in new issue
Block a user