-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.py
30 lines (25 loc) · 851 Bytes
/
logger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import logging
import os
import structlog
from structlog import get_logger
import sentry_sdk
from dotenv import load_dotenv
LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO")
if os.environ.get("SENTRY_DSN"):
sentry_sdk.init(dsn=os.environ["SENTRY_DSN"])
def get_logger(name):
structlog.configure(
processors=[
structlog.processors.TimeStamper(fmt="iso"),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.processors.KeyValueRenderer(key_prefix=" "),
structlog.processors.JSONRenderer(),
],
logger_factory=structlog.stdlib.LoggerFactory(),
cache_logger_on_first_use=True,
wrapper_class=structlog.stdlib.BoundLogger,
context_class=dict,
level=LOG_LEVEL,
)
return get_logger(name)