Skip to content

Commit

Permalink
Setup logger (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
glorialeezero authored Nov 21, 2024
2 parents 9c18e8a + 6013b8e commit 9bf5e37
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions qupsy/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import logging
import os

from rich.console import Console
from rich.logging import RichHandler

console = Console()


_log_level = os.environ.get("LOG_LEVEL")
if _log_level is not None:
_log_level = _log_level.upper()
_log_level = logging.getLevelNamesMapping()[_log_level]


_hander = RichHandler(
console=console,
show_path=_log_level is not None and _log_level == logging.DEBUG,
)

_hander.setFormatter(logging.Formatter(fmt="%(message)s", datefmt="[%X]"))

logger = logging.getLogger("quspy")
logger.addHandler(_hander)
if _log_level is not None:
logger.setLevel(_log_level)

0 comments on commit 9bf5e37

Please sign in to comment.