Configure Logging
You do not need to create a log source to send logs from the AppSignal for Python integration. An “application” log source will be created automatically. When using collector mode, AppSignal automatically instruments Python’s built-inlogging module via OpenTelemetry, attaching a handler to the root logger.
Disabling logging instrumentation
Instrumentation for Python’slogging module can be disabled using the disable_default_instrumentations configuration option:
logging module by attaching a handler to the root logger, meaning that logs sent to Python’s logging module will no longer be captured by AppSignal.
You can still send logs directly using the OpenTelemetry logs API, as described in the Sending Logs with OpenTelemetry section below.
Attaching handlers manually
When automatic instrumentation is disabled, you can attach the OpenTelemetryLoggingHandler to specific loggers yourself, rather than relying on AppSignal adding it to the root logger:
Log level
Python’slogging module defaults to WARNING, meaning INFO and DEBUG messages are not captured by default. To capture lower-severity messages, set the root logger level explicitly:
Which logs are captured
AppSignal captures logs sent to the root logger and any logger that propagates to it. Propagation is controlled by thepropagate attribute on each logger, which defaults to True in Python.
Loggers with propagate=False will not have their messages captured by AppSignal.
Framework Setup
Django
Django configures some loggers withpropagate=False by default, which prevents them from reaching AppSignal. Override these in settings.py to re-enable propagation:
"propagate": True ensures that the logger’s messages reach the root logger, where AppSignal’s handler is attached.
Attaching handlers manually
Alternatively, you can attach theLoggingHandler directly to Django’s loggers instead of relying on propagation to the root logger:
Celery
Celery forks worker processes, so AppSignal must be started for each fork. Use theworker_process_init signal to reinitialise AppSignal and configure logging in each worker process. See the Celery instrumentation page for more details on instrumenting Celery tasks.
Sending Logs with OpenTelemetry
You can also send logs directly using the OpenTelemetry logs API, without going through Python’slogging module: