diff options
author | Devaev Maxim <[email protected]> | 2018-11-17 11:20:10 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2018-11-17 11:20:10 +0300 |
commit | 43f161f9c4a39fae1538cc300237f8a62648dc86 (patch) | |
tree | 88bde2b1966309a1a87dcbe103b483c922293efd /kvmd | |
parent | 0bf39f56e26268b68bb598ae06f6f91cc3bdc0f4 (diff) |
automatic choosing journald services
Diffstat (limited to 'kvmd')
-rw-r--r-- | kvmd/apps/kvmd/__init__.py | 5 | ||||
-rw-r--r-- | kvmd/logging.py | 19 |
2 files changed, 11 insertions, 13 deletions
diff --git a/kvmd/apps/kvmd/__init__.py b/kvmd/apps/kvmd/__init__.py index 103d8be8..155b8141 100644 --- a/kvmd/apps/kvmd/__init__.py +++ b/kvmd/apps/kvmd/__init__.py @@ -22,10 +22,7 @@ def main() -> None: loop = asyncio.get_event_loop() http_session = aiohttp.ClientSession(loop=loop) - log = Log( - services=list(config["log"]["services"]), - loop=loop, - ) + log = Log(loop) hid = Hid( reset=int(config["hid"]["pinout"]["reset"]), diff --git a/kvmd/logging.py b/kvmd/logging.py index 11a8dcf1..70f6f2df 100644 --- a/kvmd/logging.py +++ b/kvmd/logging.py @@ -1,9 +1,9 @@ import sys +import re import asyncio import logging import time -from typing import List from typing import Dict from typing import AsyncGenerator @@ -24,13 +24,7 @@ def get_logger(depth: int=1) -> logging.Logger: class Log: - def __init__( - self, - services: List[str], - loop: asyncio.AbstractEventLoop, - ) -> None: - - self.__services = services + def __init__(self, loop: asyncio.AbstractEventLoop) -> None: self.__loop = loop async def poll_log(self, seek: int, follow: bool) -> AsyncGenerator[Dict, None]: @@ -38,7 +32,14 @@ class Log: reader.this_boot() reader.this_machine() reader.log_level(systemd.journal.LOG_DEBUG) - for service in self.__services: + + 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)) |