mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 02:16:41 +02:00
MDL-62907 Logging: 'other' field option to use JSON format
This commit is contained in:
parent
dafcc3cf7b
commit
75dc1756bb
9 changed files with 116 additions and 8 deletions
|
@ -43,6 +43,9 @@ trait buffered_writer {
|
|||
/** @var int $count Counter. */
|
||||
protected $count = 0;
|
||||
|
||||
/** @var bool If true, writes JSON instead of PHP serialized data for 'other' field */
|
||||
protected $jsonformat = false;
|
||||
|
||||
/**
|
||||
* Should the event be ignored (== not logged)?
|
||||
* @param \core\event\base $event
|
||||
|
@ -69,7 +72,11 @@ trait buffered_writer {
|
|||
// at the same time this lowers memory use because
|
||||
// snapshots and custom objects may be garbage collected.
|
||||
$entry = $event->get_data();
|
||||
$entry['other'] = serialize($entry['other']);
|
||||
if ($this->jsonformat) {
|
||||
$entry['other'] = json_encode($entry['other']);
|
||||
} else {
|
||||
$entry['other'] = serialize($entry['other']);
|
||||
}
|
||||
$entry['origin'] = $PAGE->requestorigin;
|
||||
$entry['ip'] = $PAGE->requestip;
|
||||
$entry['realuserid'] = \core\session\manager::is_loggedinas() ? $GLOBALS['USER']->realuser : null;
|
||||
|
|
|
@ -49,7 +49,7 @@ class helper {
|
|||
$extra = ['origin' => $data->origin, 'ip' => $data->ip, 'realuserid' => $data->realuserid];
|
||||
$data = (array) $data;
|
||||
$id = $data['id'];
|
||||
$data['other'] = unserialize($data['other']);
|
||||
$data['other'] = \logstore_standard\log\store::decode_other($data['other']);
|
||||
if ($data['other'] === false) {
|
||||
$data['other'] = [];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue