Skip to content

Commit

Permalink
feat: ignore loggers from third party libraries (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
vncsna authored Nov 12, 2023
1 parent 84c5795 commit 6a8447a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
10 changes: 3 additions & 7 deletions bd_api/custom/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def emit(self, record: LogRecord):

def setup_logger(
level: str = "INFO",
ignore: list[str] = [],
serialize: bool = False,
format: str = "[{time:YYYY-MM-DD HH:mm:ss}] <lvl>{message}</>",
):
Expand All @@ -36,6 +37,8 @@ def setup_logger(
for name in root.manager.loggerDict.keys():
getLogger(name).handlers = []
getLogger(name).propagate = True
if name in ignore:
getLogger(name).setLevel("ERROR")

logger.remove()

Expand All @@ -45,10 +48,3 @@ def setup_logger(
format=format,
serialize=serialize,
)
logger.add(
"debug.log",
level="DEBUG",
format=format,
rotation="30 MB",
retention="7 days",
)
2 changes: 1 addition & 1 deletion bd_api/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
DEFAULT_FROM_EMAIL = getenv("EMAIL_HOST_USER")

# Logging
setup_logger(level="DEBUG", serialize=False)
setup_logger(level="DEBUG", ignore=["faker"], serialize=False)

# Google Application Credentials
GOOGLE_APPLICATION_CREDENTIALS = getenv("GOOGLE_APPLICATION_CREDENTIALS")
Expand Down
2 changes: 1 addition & 1 deletion bd_api/settings/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
DEFAULT_FROM_EMAIL = getenvp("EMAIL_HOST_USER")

# Logging
setup_logger(level="INFO", serialize=True)
setup_logger(level="INFO", ignore=["faker"], serialize=True)

# Google Application Credentials
GOOGLE_APPLICATION_CREDENTIALS = getenvp("GOOGLE_APPLICATION_CREDENTIALS", "")
Expand Down

0 comments on commit 6a8447a

Please sign in to comment.