summaryrefslogtreecommitdiff
path: root/kvmd/logging.py
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2018-11-18 08:21:55 +0300
committerDevaev Maxim <[email protected]>2018-11-18 08:21:55 +0300
commit1e44482a849b3f605c95251fc59ff571e7d25a3b (patch)
tree7cf7defc9d21fcda62ba2e4c1845093ed55f6439 /kvmd/logging.py
parentf38dc912d3069862efe5afa33a563a576c9ddfa2 (diff)
refactoring
Diffstat (limited to 'kvmd/logging.py')
-rw-r--r--kvmd/logging.py47
1 files changed, 0 insertions, 47 deletions
diff --git a/kvmd/logging.py b/kvmd/logging.py
index 70f6f2df..838e13d1 100644
--- a/kvmd/logging.py
+++ b/kvmd/logging.py
@@ -1,13 +1,5 @@
import sys
-import re
-import asyncio
import logging
-import time
-
-from typing import Dict
-from typing import AsyncGenerator
-
-import systemd.journal
# =====
@@ -21,42 +13,3 @@ def get_logger(depth: int=1) -> logging.Logger:
break
name = frames[depth].f_globals["__name__"]
return logging.getLogger(name)
-
-
-class Log:
- def __init__(self, loop: asyncio.AbstractEventLoop) -> None:
- self.__loop = loop
-
- async def poll_log(self, seek: int, follow: bool) -> AsyncGenerator[Dict, None]:
- reader = systemd.journal.Reader()
- reader.this_boot()
- reader.this_machine()
- reader.log_level(systemd.journal.LOG_DEBUG)
-
- services = set(
- service
- for service in systemd.journal.Reader().query_unique("_SYSTEMD_UNIT")
- if re.match(r"kvmd(-\w+)?\.service", service)
- ).union(["kvmd.service"])
-
- for service in services:
- reader.add_match(_SYSTEMD_UNIT=service)
- if seek > 0:
- reader.seek_realtime(float(time.time() - seek))
-
- for entry in reader:
- yield self.__entry_to_record(entry)
-
- while follow:
- entry = reader.get_next()
- if entry:
- yield self.__entry_to_record(entry)
- else:
- await asyncio.sleep(1)
-
- def __entry_to_record(self, entry: Dict) -> Dict[str, Dict]:
- return {
- "dt": entry["__REALTIME_TIMESTAMP"],
- "service": entry["_SYSTEMD_UNIT"],
- "msg": entry["MESSAGE"].rstrip(),
- }