From 43f161f9c4a39fae1538cc300237f8a62648dc86 Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Sat, 17 Nov 2018 11:20:10 +0300 Subject: automatic choosing journald services --- kvmd/apps/kvmd/__init__.py | 5 +---- kvmd/logging.py | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 13 deletions(-) (limited to 'kvmd') 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)) -- cgit v1.2.3