Redirect logger to stderr.

This commit is contained in:
Sleepy Monax 2023-02-06 18:12:14 +01:00
parent 627c4aa4f0
commit 07a10f192d
2 changed files with 9 additions and 5 deletions

View file

@ -1,3 +1,4 @@
import sys
import osdk.vt100 as vt100
@ -8,10 +9,13 @@ class Logger:
self.name = name
def log(self, message: str):
print(f"{vt100.CYAN}[{self.name}]{vt100.RESET} {message}")
print(
f"{vt100.CYAN}[{self.name}]{vt100.RESET} {message}", file=sys.stderr)
def warn(self, message: str):
print(f"{vt100.YELLOW}[{self.name}]{vt100.RESET} {message}")
print(
f"{vt100.YELLOW}[{self.name}]{vt100.RESET} {message}", file=sys.stderr)
def error(self, message: str):
print(f"{vt100.RED}[{self.name}]{vt100.RESET} {message}")
print(
f"{vt100.RED}[{self.name}]{vt100.RESET} {message}", file=sys.stderr)

View file

@ -28,13 +28,13 @@ def title(text: str):
print(f"{LIGHT_WHITE}{text}{RESET}:")
def wordwrap(text: str, width: int = 60) -> str:
def wordwrap(text: str, width: int = 60, newline="\n") -> str:
result = ""
curr = 0
for c in text:
if c == " " and curr > width:
result += "\n"
result += newline
curr = 0
else:
result += c