From 72bec60e3712378231cec1f0cfbc0d55fa306846 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Mon, 2 Feb 2026 10:09:25 +0000 Subject: [PATCH] Add formatters (table, JSON, text) --- loglens/formatters/base.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/loglens/formatters/base.py b/loglens/formatters/base.py index c7debd7..b7063ba 100644 --- a/loglens/formatters/base.py +++ b/loglens/formatters/base.py @@ -1,13 +1,28 @@ +"""Base formatter class.""" + from abc import ABC, abstractmethod -from typing import Any - -from loglens.analyzers.analyzer import AnalysisResult +from typing import Any, Optional, TextIO -class Formatter(ABC): - """Base formatter class.""" +class OutputFormatter(ABC): + """Abstract base class for output formatters.""" + + def __init__(self, output: Optional[TextIO] = None): + self.output = output @abstractmethod - def format(self, result: AnalysisResult) -> str: - """Format the analysis result.""" + def format(self, data: Any) -> str: + """Format data for output.""" pass + + def write(self, text: str) -> None: + """Write to output stream.""" + if self.output: + self.output.write(text) + else: + print(text, end="") + + def flush(self) -> None: + """Flush output stream.""" + if self.output: + self.output.flush()