34 lines
878 B
Python
34 lines
878 B
Python
"""
|
|
Simple logging implementation that wraps long messages to 80 characters,
|
|
indents multi-line messages, and uses colors for errors (red), warnings
|
|
(yellow), and success (green), and prints output to STDERR only.
|
|
"""
|
|
|
|
import sys
|
|
import textwrap
|
|
|
|
from termcolor import colored
|
|
|
|
|
|
def _eprint(message: str):
|
|
print(message, file=sys.stderr)
|
|
|
|
|
|
def _wrap(message: str, prefix: str):
|
|
return textwrap.wrap(message, 80, initial_indent=f"{prefix} ", subsequent_indent=" " * (len(prefix) + 1))
|
|
|
|
|
|
def success(message: str):
|
|
_eprint(colored("\n".join(_wrap(message, "•")), "green"))
|
|
|
|
|
|
def info(message: str):
|
|
_eprint(colored("\n".join(_wrap(message, "•")), "grey"))
|
|
|
|
|
|
def warn(message: str):
|
|
_eprint(colored("\n".join(_wrap(message, "WARNING:")), "yellow"))
|
|
|
|
|
|
def error(message: str):
|
|
_eprint(colored("\n".join(_wrap(message, "ERROR:")), "red", attrs=["dark"]))
|