-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: properly configure logging in cli (#447)
Largely a copy/paste of work done in metakb. Small QOL increase for running data updates.
- Loading branch information
1 parent
d8b6b68
commit 9690f95
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""Provide functions and utilities related to application logging.""" | ||
|
||
import logging | ||
|
||
|
||
def _quiet_upstream_libs() -> None: | ||
"""Turn off debug logging for chatty upstream library loggers.""" | ||
for lib in ( | ||
"boto3", | ||
"botocore", | ||
"urllib3", | ||
): | ||
logging.getLogger(lib).setLevel(logging.INFO) | ||
|
||
|
||
def configure_logs( | ||
log_file: str | None = None, | ||
log_level: int = logging.DEBUG, | ||
quiet_upstream: bool = True, | ||
) -> None: | ||
"""Configure logging. | ||
:param log_filename: location to put log file at | ||
:param log_level: global log level to set | ||
:param quiet_upstream: if True, turn off debug logging for a selection of libraries | ||
""" | ||
if log_file is None: | ||
log_file = "therapy.log" | ||
if quiet_upstream: | ||
_quiet_upstream_libs() | ||
logging.basicConfig( | ||
filename=log_file, | ||
format="[%(asctime)s] - %(name)s - %(levelname)s : %(message)s", | ||
) | ||
logger = logging.getLogger(__package__) | ||
logger.setLevel(log_level) |