Skip to content

Commit

Permalink
setup logging upon importing the package
Browse files Browse the repository at this point in the history
This is done by exposing the setup_logging method that applies the formatting & log level
  • Loading branch information
shtlrs authored and supakeen committed Mar 9, 2024
1 parent 049421a commit 0965564
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/pinnwand/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .logger import setup_logging

setup_logging()
16 changes: 8 additions & 8 deletions src/pinnwand/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
LoggerClass = logging.getLoggerClass()


def get_logger(name: str) -> LoggerClass:
logger = logging.getLogger(name)
def setup_logging():
"""Sets up basic log levels & formats."""
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s | %(name)s | %(levelname)s | %(message)s",
)

for handler in logger.handlers:
formatter = logging.Formatter(
"%(asctime)s | %(name)s | %(levelname)s | %(message)s"
)
handler.setFormatter(formatter)

return logger
def get_logger(name: str) -> LoggerClass:
return logging.getLogger(name)

0 comments on commit 0965564

Please sign in to comment.