Files
logmon/modules/base.py
Mateusz Gruszczyński 7b41672d05 upload
2025-10-28 21:27:10 +01:00

55 lines
1.6 KiB
Python

"""
Bazowa klasa dla modułów monitorowania logów
"""
import logging
import time
import threading
class LogModule:
"""Bazowa klasa dla modułów monitorowania"""
def __init__(self, config, daemon):
"""
Args:
config: ConfigParser object z konfiguracją
daemon: Referencja do głównego demona
"""
self.config = config
self.daemon = daemon
self.logger = logging.getLogger(self.__class__.__name__)
self.running = False
self.thread = None
def start(self):
"""Uruchamia moduł w osobnym wątku"""
if self.running:
self.logger.warning("Module already running")
return
self.running = True
self.thread = threading.Thread(target=self._run, daemon=True)
self.thread.start()
self.logger.info(f"{self.__class__.__name__} started")
def stop(self):
"""Zatrzymuje moduł"""
self.running = False
if self.thread and self.thread.is_alive():
self.thread.join(timeout=5)
self.logger.info(f"{self.__class__.__name__} stopped")
def _run(self):
"""Główna pętla modułu - do nadpisania w klasach potomnych"""
raise NotImplementedError("Subclasses must implement _run()")
def process_line(self, line):
"""
Przetwarza pojedynczą linię logu
Args:
line: Linia tekstu z logu
"""
raise NotImplementedError("Subclasses must implement process_line()")