Attention
The log handlers included here work great but we suspect some improvements could be made
to the structure of the logs to give fuller / more easily filterable results, especially
around trace
/span
and the contents of the httpRequest
object. Pick up the issue here: PRs are welcome!
Logging¶
Tip
Quickly set up logging out of the box, by dropping the LOGGING entry from the example test server
into your settings.py
.
Structured logs¶
On Google Cloud, if you use structured logging, your entries can be filtered and inspected much more powerfully than if you log in plain text.
Django has its own default logging configuration, and we need to do some
tweaking to it to make sure we capture the information in a structured way. Notice particularly that the django
and django.server
modules have specific setups to record,
for example, request-level information.
django-gcp
provides django_gcp.logging.GoogleStructuredLogsHandler
to add django-specific
behaviour to the Google StructuredLogsHandler
that is used under the hood.
Error Reporting¶
This isn’t the same thing as structured logging.
If you use Google Cloud Error Reporting (as opposed to sentry or similar), django-gcp
provides
a handler enabling you to send errors/exceptions directly from django. Then you can configure Error Reporting
as you wish (eg to track unresolved errors, email teams, connect issue trackers, etc).
django-gcp
provides django_gcp.logging.GoogleErrorReportingHandler
to do this. You need to set the
GCP_ERROR_REPORTING_SERVICE_NAME
value in your settings.py.