Skip to content

Commit cde57f0

Browse files
mnocondabrt
andcommitted
Doc for disabling activity log (#3182)
* Doc for disabling activity log * Apply suggestions from code review Co-authored-by: Tomasz Dąbrowski <64841871+dabrt@users.noreply.github.com> * Apply suggestion from @mnocon * Review feedback * Fixed example * Added mention * Apply suggestion from @mnocon --------- Co-authored-by: Tomasz Dąbrowski <64841871+dabrt@users.noreply.github.com>
1 parent 30b1f48 commit cde57f0

2 files changed

Lines changed: 62 additions & 10 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php declare(strict_types=1);
2+
3+
/** @var \Ibexa\Contracts\ActivityLog\ActivityLogServiceInterface $activityLogService */
4+
$activityLogService->disable();
5+
6+
// Perform operations that should not be logged to the activity log
7+
// ...
8+
9+
$activityLogService->enable();

docs/administration/recent_activity/recent_activity.md

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,62 @@ Recent activity log displays last actions in the repository (whatever their orig
1010

1111
To learn more about its back office usage and the actions logged by default, see [Recent activity in User Documentation]([[= user_doc =]]/recent_activity/recent_activity/).
1212

13-
## Configuration and cronjob
13+
## Configuration
1414

15-
With some configuration, you can customize the log length in the database or on screen.
15+
With some configuration, you can customize the log length in the database or on screen, or disable the logging completely.
1616
A command maintains the log size in database, it should be scheduled through CRON.
1717

18-
- The configuration `ibexa.system.<scope>.activity_log.pagination.activity_logs_limit` sets the number of log items shown per page in the back office (default value: 25).
19-
A log item is a group of entries, or an entry without group.
20-
- The configuration `ibexa.repositories.<repository>.activity_log.truncate_after_days` sets the number of days a log entry is kept before it's deleted by the `ibexa:activity-log:truncate` command (default value: 30 days).
18+
### Log retention
19+
20+
The `ibexa.repositories.<repository>.activity_log.truncate_after_days` setting sets the number of days a log entry is kept before it's deleted by the `ibexa:activity-log:truncate` command (default value: 30 days).
2121

22-
For example, the following configuration sets 15 days of life to the log entries on the `default` repository, and 20 context groups per page for the `admin_group` SiteAccess group:
22+
For example, the following configuration sets 15 days of life to the log entries on the `default` repository:
2323

2424
```yaml
2525
ibexa:
2626
repositories:
2727
default:
2828
activity_log:
2929
truncate_after_days: 15
30+
```
31+
32+
To automate a regular truncation, the command `ibexa:activity-log:truncate` must be added to a crontab.
33+
To minimize the number of entries to delete, it's recommended to execute the command more than one time a day.
34+
35+
For every exact hour, the cronjob line is:
36+
`0 * * * * cd [path-to-ibexa]; php bin/console ibexa:activity-log:truncate --quiet --env=prod`
37+
38+
### Display limit
39+
40+
The `ibexa.system.<scope>.activity_log.pagination.activity_logs_limit` setting sets the number of log items shown per page in the back office (default value: 25).
41+
42+
For example, the following configuration sets 20 context groups per page for the `admin_group` SiteAccess group:
43+
44+
```yaml
45+
ibexa:
3046
system:
3147
admin_group:
3248
activity_log:
3349
pagination:
3450
activity_logs_limit: 20
3551
```
52+
A log item is a group of entries, or an entry without group.
3653

37-
To automate a regular truncation, the command `ibexa:activity-log:truncate` must be added to a crontab.
38-
To minimize the number of entries to delete, it's recommended to execute the command more than one time a day.
54+
### Disable activity log
3955

40-
For every exact hour, the cronjob line is:
41-
`0 * * * * cd [path-to-ibexa]; php bin/console ibexa:activity-log:truncate --quiet --env=prod`
56+
The `ibexa.repositories.<repository>.activity_log.enabled` setting can disable activity log entirely for a given [repository](repository_configuration.md).
57+
58+
For example, to disable the activity log for the `default` repository:
59+
60+
```yaml
61+
ibexa:
62+
repositories:
63+
default:
64+
activity_log:
65+
enabled: false
66+
```
67+
68+
You can also disable activity log for a single action by using the [PHP API](#disable-logging-activities).
4269

4370
## Permission and security
4471

@@ -132,6 +159,7 @@ migration
132159
Keep activity logging as light as possible.
133160
Don't make database requests or heavy computation at logging time.
134161
Keep them for activity log list display time.
162+
If needed, you can [disable logging for specific operations](#disable-logging-activities) using the PHP API.
135163

136164
#### Create an entry
137165

@@ -259,6 +287,21 @@ Thanks to the previous subscriber, the related object is available at display ti
259287
[[= include_code('code_samples/recent_activity/templates/themes/admin/activity_log/ui/my_feature/simulate.html.twig') =]]
260288
```
261289

290+
### Disable logging activities
291+
292+
You can disable logging the activities with PHP API, for example, when loading large amounts of data in cases where you don't want logging to slow down the process or the actions to be included in the log.
293+
294+
Call [`ActivityLogService::disable()`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ActivityLog-ActivityLogServiceInterface.html#method_disable)
295+
before running the relevant code, then [`ActivityLogService::enable()`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ActivityLog-ActivityLogServiceInterface.html#method_enable) to restore the logging process:
296+
297+
``` php
298+
[[= include_code('code_samples/recent_activity/src/recent_activity_disable.php') =]]
299+
```
300+
301+
When disabled, any call to [`ActivityLogService::save()`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ActivityLog-ActivityLogServiceInterface.html#method_save) has no effect and no entries are written to the database.
302+
303+
You can check the current state with [`ActivityLogService::isEnabled()`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ActivityLog-ActivityLogServiceInterface.html#method_isEnabled) and [`ActivityLogService::isDisabled()`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ActivityLog-ActivityLogServiceInterface.html#method_isDisabled).
304+
262305
## REST API
263306

264307
You can browse activity logs with REST API.

0 commit comments

Comments
 (0)