Skip to content

Commit

Permalink
Merge pull request #67 from paugier/fix/log
Browse files Browse the repository at this point in the history
Avoid logging.basicConfig
  • Loading branch information
ashwinvis committed Nov 10, 2022
2 parents 8cf10ac + cd76b85 commit 52f327e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pymech/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""
import os
import logging
from typing import Union

logger = logging.getLogger("pymech")

Expand All @@ -23,13 +24,15 @@
# Set a nice colored output
from rich.logging import RichHandler

handler = RichHandler()
logger.addHandler(handler)
handler: Union[RichHandler, logging.StreamHandler] = RichHandler()
except ImportError:
# No color available, use default config
logging.basicConfig(format="%(levelname)s: %(message)s")
logger.info("Disabling color, you really want to install colorlog.")
handler = logging.StreamHandler()
formatter = logging.Formatter("%(levelname)s: %(message)s")
handler.setFormatter(formatter)
logger.info("Disabling coloured logs; if needed you should `pip install rich`.")

logger.addHandler(handler)

if bool(os.getenv("PYMECH_DEBUG")):
logger.setLevel(logging.DEBUG)
Expand Down

0 comments on commit 52f327e

Please sign in to comment.