-
Notifications
You must be signed in to change notification settings - Fork 0
/
tide_logs.module
36 lines (29 loc) · 1.03 KB
/
tide_logs.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
/**
* Implements hook_admin_audit_trail_log_alter().
*
* Responds to admin_audit_trail events and forwards it to tide_logs otel collector.
*/
function tide_logs_admin_audit_trail_log_alter(&$log) {
$channel = sprintf("admin_audit_trail_%s", $log["type"]);
// Strip out properties that are unnecessary.
$filtered_log = $log;
unset(
$filtered_log["lid"],
$filtered_log["type"],
$filtered_log["created"],
$filtered_log["ip"],
$filtered_log["ref_entity"],
);
// Remove markup from text fields.
$filtered_log['description'] = preg_replace('/[\x{200B}-\x{200D}]/u', '', strip_tags($filtered_log['description']));
$filtered_log['ref_char'] = preg_replace('/[\x{200B}-\x{200D}]/u', '', $filtered_log['ref_char']);
// json not supported in watchdog messages. Using a comma-delimited list
// in key:value format.
$items = [];
foreach ($filtered_log as $key => $value) {
$items[] = sprintf("%s:%s", $key, $value);
}
$message = implode(", ", $items);
\Drupal::logger($channel)->notice($message);
}