Skip to content

Logging

Integrates leverages Python’s logging library to log important events and errors.

This setup aids in debugging the application, identifying code issues, and tracking transactional events for security purposes.

The full configuration can be found in the back/integrates/settings/logger.py file.

Handlers

Console

Console logging is primarily used during development. It offers a convenient way to monitor application activity directly in the terminal.

import logging
LOGGER = logging.getLogger(__name__)
def main() -> None:
LOGGER.info(...)

Bugsnag

Bugsnag is employed to report both handled and unhandled errors in the application.

These reports can be examined in the Bugsnag UI, providing contextual details and stack traces to facilitate quick debugging and resolution.

import logging
LOGGER = logging.getLogger(__name__)
def main() -> None:
LOGGER.warning(...)
LOGGER.error(...)
LOGGER.exception(...)

Access Bugsnag by signing into your Okta account. If the app is not visible, request access through help@fluidattacks.com.

Watchtower

Watchtower is utilized in production to send detailed transactional logs to Amazon CloudWatch, capturing all significant events within the application.

import logging
TRANSACTIONAL_LOGGER = logging.getLogger("transactional")
def main() -> None:
TRANSACTIONS_LOGGER.info(
"Organization was successfully added",
extra={
"organization_id": "123",
"organization_name": "test_organization",
"user_email": "test_user",
},
)

Access Amazon CloudWatch by signing into your Okta account. If the AWS app is not visible, request access through help@fluidattacks.com.

Development considerations

Async handlers

When configuring a new logging handler, consider that async functions are extensively used within the codebase.

To avoid blocking the event loop, configure the handler for async compatibility, such as utilizing native asyncio support or employing a queue with separate thread processing (a boolean flag usually enables this).

Refer to the library documentation or consult the maintainer for detailed information.