Wagtail provides a mechanism to log actions performed on its objects. Common activities such as page creation, update, deletion, locking and unlocking, revision scheduling, and privacy changes are automatically logged at the model level.
:param action: The code name for the action being performed. This can be one of the names listed below or a custom action defined through the :ref:`register_log_actions` hook.
:param uuid: Optional - log entries given the same UUID indicates that they occurred as part of the same user action (for example a page being immediately published on creation).
:param title: The string representation, of the instance being logged. By default, Wagtail will attempt to use the instance's ``str`` representation or ``get_admin_display_title`` for page objects.
When adding logging, you need to log the action or actions that happen to the object. For example, if the user creates and publishes a page, there should be a "create" entry and a "publish" entry. Or, if the user copies a published page and chooses to keep it published, there should be a "copy" and a "publish" entry for the new page.
The `wagtail.log_actions` module provides a context manager to simplify code that logs a large number of actions,
such as import scripts:
```python
from wagtail.log_actions import LogContext
with LogContext(user=User.objects.get(username='admin')):
# ...
log(page, 'wagtail.edit')
# ...
log(page, 'wagtail.publish')
```
All `log` calls within the block will then be attributed to the specified user, and assigned a common UUID. A log context is created automatically for views within the Wagtail admin.
## Log models
Logs are stored in the database via the models `wagtail.models.PageLogEntry` (for actions on Page instances) and
`wagtail.models.ModelLogEntry` (for actions on all other models). Page logs are stored in their own model to
ensure that reports can be filtered according to the current user's permissions, which could not be done efficiently
with a generic foreign key.
If your own models have complex reporting requirements that would make `ModelLogEntry` unsuitable, you can configure
them to be logged to their own log model; this is done by subclassing the abstract `wagtail.models.BaseLogEntry`
model, and registering that model with the log registry's `register_model` method:
```python
from myapp.models import Sprocket, SprocketLogEntry
# here SprocketLogEntry is a subclass of BaseLogEntry