Skip to content

Commit

Permalink
Tweak log styles
Browse files Browse the repository at this point in the history
Use Rich's default log format, but change warning to yellow to
differentiate it more from error.
  • Loading branch information
clenk committed Feb 21, 2024
1 parent 0e8acd6 commit 8171248
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import asyncio
import logging
import os
from rich.console import Console
from rich.logging import RichHandler
from rich.theme import Theme
import sys
import warnings
import subprocess
Expand Down Expand Up @@ -36,16 +38,17 @@


def setup_logger(level=logging.DEBUG):
format = "%(asctime)s - %(levelname)-5s (%(filename)s:%(lineno)s %(funcName)s) %(message)s"
format = "%(message)s"
datefmt = "%Y-%m-%d %H:%M:%S"
if no_color():
logging.basicConfig(level=level, format=format, datefmt=datefmt)
else:
console = Console(theme=Theme({"logging.level.warning": "yellow"}))
logging.basicConfig(
level=level,
format=format,
datefmt=datefmt,
handlers=[RichHandler(rich_tracebacks=True, markup=True, show_time=False)]
handlers=[RichHandler(rich_tracebacks=True, markup=True, console=console)]
)

for logger_name in logging.root.manager.loggerDict.keys():
Expand Down

0 comments on commit 8171248

Please sign in to comment.