diff options
author | Stefan Hertrampf <stefan.hertrampf@cyberus-technology.de> | 2024-04-08 15:41:33 +0200 |
---|---|---|
committer | Stefan Hertrampf <stefan.hertrampf@cyberus-technology.de> | 2024-05-07 15:17:15 +0200 |
commit | b505db6f6df1f67ba437e60d7070a8f6698f6113 (patch) | |
tree | dc3974c5b2d1810fd700806bf5c2e5e299b77aff /nixos/lib | |
parent | a6160e576347358db79071cf2e4ee5dc623ce7ec (diff) |
nixos/test-driver: add AbstractLogger interface
Diffstat (limited to 'nixos/lib')
-rw-r--r-- | nixos/lib/test-driver/test_driver/logger.py | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/nixos/lib/test-driver/test_driver/logger.py b/nixos/lib/test-driver/test_driver/logger.py index 77a9b81c5946c..14c5b1033dd50 100644 --- a/nixos/lib/test-driver/test_driver/logger.py +++ b/nixos/lib/test-driver/test_driver/logger.py @@ -3,6 +3,7 @@ import os import sys import time import unicodedata +from abc import ABC, abstractmethod from contextlib import contextmanager from queue import Empty, Queue from typing import Any, Dict, Iterator @@ -12,7 +13,43 @@ from xml.sax.xmlreader import AttributesImpl from colorama import Fore, Style -class Logger: +class AbstractLogger(ABC): + @abstractmethod + def log(self, message: str, attributes: Dict[str, str] = {}) -> None: + pass + + @abstractmethod + @contextmanager + def subtest(self, name: str, attributes: Dict[str, str] = {}) -> Iterator[None]: + pass + + @abstractmethod + @contextmanager + def nested(self, message: str, attributes: Dict[str, str] = {}) -> Iterator[None]: + pass + + @abstractmethod + def info(self, *args, **kwargs) -> None: # type: ignore + pass + + @abstractmethod + def warning(self, *args, **kwargs) -> None: # type: ignore + pass + + @abstractmethod + def error(self, *args, **kwargs) -> None: # type: ignore + pass + + @abstractmethod + def log_serial(self, message: str, machine: str) -> None: + pass + + @abstractmethod + def print_serial_logs(self, enable: bool) -> None: + pass + + +class Logger(AbstractLogger): def __init__(self) -> None: self.logfile = os.environ.get("LOGFILE", "/dev/null") self.logfile_handle = codecs.open(self.logfile, "wb") @@ -110,4 +147,4 @@ class Logger: self.xml.endElement("nest") -rootlog = Logger() +rootlog: AbstractLogger = Logger() |