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.
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. Some libraries and frameworks set this attribute on their own loggers. Django, for example, sets it on django.server, which the Django section shows how to override.
Set the log level
Python’slogging module defaults to the WARNING log level, meaning that INFO and DEBUG log messages won’t be captured. To capture lower-severity messages, set the root logger level:
Send only specific loggers to AppSignal
By default AppSignal captures everything that reaches the root logger. To send a chosen set of loggers instead, disable the automatic instrumentation with thedisable_default_instrumentations configuration option and attach the handler yourself:
log_code_attributes=True to record the file, function, and line each log line came from, as the automatic instrumentation does.
A handler you attach yourself is not protected against later reconfiguration the way the automatic instrumentation is. For Django, adding it to the logging configuration itself is the most reliable way to attach it.
Framework setup
Celery
Celery forks worker processes, so AppSignal must be started for each fork. Use theworker_process_init signal to reinitialize AppSignal and configure logging in each worker process. See the Celery instrumentation page for more details on instrumenting Celery tasks.
Django
Django setspropagate=False on its django.server logger, so its messages do not reach the root logger where AppSignal’s handler is attached. Override it in your LOGGING setting:
LOGGING setting rather than attaching it in code, so that it survives Django configuring the logging module:
Sending logs with OpenTelemetry
You can also send logs directly using the OpenTelemetry logs API, without going through Python’slogging module:
message key becomes the log line’s message:
Filtering logs
You can use theignore_logs configuration option to ignore log lines. See our Ignore Logs guide to learn more.