Add formatters: table, JSON, text and config
Some checks failed
Some checks failed
This commit is contained in:
28
loglens/formatters/base.py
Normal file
28
loglens/formatters/base.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
"""Base formatter class."""
|
||||||
|
|
||||||
|
from abc import ABC, abstractmethod
|
||||||
|
from typing import Any, Dict, List, TextIO
|
||||||
|
|
||||||
|
|
||||||
|
class OutputFormatter(ABC):
|
||||||
|
"""Abstract base class for output formatters."""
|
||||||
|
|
||||||
|
def __init__(self, output: TextIO = None):
|
||||||
|
self.output = output
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
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()
|
||||||
Reference in New Issue
Block a user