diff options
author | 2022-05-30 19:57:45 -0700 | |
---|---|---|
committer | 2022-05-30 19:57:45 -0700 | |
commit | 8f62c90a96e3634c2d41cda96afefaff5c1fb54d (patch) | |
tree | 07f9a21a57306267a864123558b1a00ed32bd680 /snekbox/utils/logging.py | |
parent | Move coverage config into pyproject.toml (diff) |
Move logging code to separate utility modules
Diffstat (limited to '')
-rw-r--r-- | snekbox/utils/logging.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/snekbox/utils/logging.py b/snekbox/utils/logging.py new file mode 100644 index 0000000..e5afd0c --- /dev/null +++ b/snekbox/utils/logging.py @@ -0,0 +1,33 @@ +import logging +import os +import sys + +import sentry_sdk +from sentry_sdk.integrations.falcon import FalconIntegration + +__all__ = ("FORMAT", "init_logger", "init_sentry") + +FORMAT = "%(asctime)s | %(process)5s | %(name)30s | %(levelname)8s | %(message)s" + + +def init_logger(debug: bool) -> None: + """Initialise the root logger with a handler that outputs to stdout.""" + log = logging.getLogger("snekbox") + log.setLevel(logging.DEBUG if debug else logging.INFO) + log.propagate = True + + formatter = logging.Formatter(FORMAT) + handler = logging.StreamHandler(sys.stdout) + handler.setFormatter(formatter) + log.addHandler(handler) + + +def init_sentry() -> None: + """Initialise the Sentry SDK.""" + git_sha = os.environ.get("GIT_SHA", "development") + sentry_sdk.init( + dsn=os.environ.get("SNEKBOX_SENTRY_DSN", ""), + integrations=[FalconIntegration()], + send_default_pii=True, + release=f"snekbox@{git_sha}" + ) |