Add formatters (table, JSON, text)
Some checks failed
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / test (3.9) (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / build (push) Has been cancelled
CI / test (3.10) (push) Has been cancelled

This commit is contained in:
2026-02-02 10:09:25 +00:00
parent d9812fc17c
commit 72bec60e37

View File

@@ -1,13 +1,28 @@
"""Base formatter class."""
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import Any from typing import Any, Optional, TextIO
from loglens.analyzers.analyzer import AnalysisResult
class Formatter(ABC): class OutputFormatter(ABC):
"""Base formatter class.""" """Abstract base class for output formatters."""
def __init__(self, output: Optional[TextIO] = None):
self.output = output
@abstractmethod @abstractmethod
def format(self, result: AnalysisResult) -> str: def format(self, data: Any) -> str:
"""Format the analysis result.""" """Format data for output."""
pass 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()