Logging
June 9, 2025 ยท View on GitHub
The CMS implements logging that conforms to the ONS Logging standards
This is done by creating a custom log formatter classes (ref), and setting up the Django logging settings to use them.
Developer notes
To start with, read the Django logging documentation.
In most cases, one would
# cms/path/to/my_module.py
import logging
logger = logging.getLogger(__name__)
...
logger.info("This is my log message")
To include extra data, use the extra keyword argument, which takes a dictionary with the extra data to pass on.
# cms/path/to/my_module.py
import logging
logger = logging.getLogger(__name__)
...
logger.info("Extra data", extra={"data": 123})
You can see an example in cms/bundles/management/commands/publish_bundles.py:
logger.info(
"Publishing Bundle",
extra={
"bundle_id": bundle_id,
"event": "publishing_bundle",
},
)