function jsonlog_example_entry in JSONlog 8
Same name and namespace in other branches
- 8.2 jsonlog.inc \jsonlog_example_entry()
- 3.x jsonlog.inc \jsonlog_example_entry()
Helper function to gather data as an example in admin screen
Parameters
\Drupal\jsonlog\Logger\JsonLogData $entry:
Return value
array with table #header and #rows
1 call to jsonlog_example_entry()
- _jsonlog_form_system_logging_settings_alter in ./
jsonlog.inc - Adds this module's setting fields to the system logging settings form.
File
- ./
jsonlog.inc, line 423 - JSONlog module helper functions.
Code
function jsonlog_example_entry($entry) {
// JSON fields.
$json_fields = [
'message' => [
'label' => t('Message', [], [
'context' => 'module:jsonlog',
]),
'value' => $entry
->getData()['message'],
],
'@timestamp' => [
'label' => t('Timestamp', [], [
'context' => 'module:jsonlog',
]),
'value' => $entry
->getData()['@timestamp'],
],
'@version' => [
'label' => t('Version', [], [
'context' => 'module:jsonlog',
]),
'value' => $entry
->getData()['@version'],
],
'message_id' => [
'label' => t('Message ID (@site_id + unique ID)', [
'@site_id' => $entry
->getData()['site_id'],
], [
'context' => 'module:jsonlog',
]),
'value' => $entry
->getData()['message_id'],
],
'site_id' => [
'label' => t('Site ID', [], [
'context' => 'module:jsonlog',
]),
'value' => $entry
->getData()['site_id'],
],
'canonical' => [
'label' => t('Canonical', [], [
'context' => 'module:jsonlog',
]),
'value' => $entry
->getData()['canonical'],
],
'tags' => [
'label' => t('Tags (null or array of strings)', [], [
'context' => 'module:jsonlog',
]),
'value' => $entry
->getData()['tags'],
],
'type' => [
'label' => t('Type', [], [
'context' => 'module:jsonlog',
]),
'value' => $entry
->getData()['type'],
],
'subtype' => [
'label' => t('Subtype (Rfc \'type\')', [], [
'context' => 'module:jsonlog',
]),
'value' => $entry
->getData()['subtype'],
],
'severity' => [
'label' => t('Severity', [], [
'context' => 'module:jsonlog',
]),
'value' => $entry
->getData()['severity'],
],
'method' => [
'label' => t('Request method (GET, POST, cli)', [], [
'context' => 'module:jsonlog',
]),
'value' => $entry
->getData()['method'],
],
'request_uri' => [
'label' => t('Request URI', [], [
'context' => 'module:jsonlog',
]),
'value' => $entry
->getData()['request_uri'],
],
'referer' => [
'label' => t('Referer', [], [
'context' => 'module:jsonlog',
]),
'value' => $entry
->getData()['referer'],
],
'uid' => [
'label' => t('User ID', [], [
'context' => 'module:jsonlog',
]),
'value' => $entry
->getData()['uid'],
],
'username' => [
'label' => t('Username (when not anonymous user)', [], [
'context' => 'module:jsonlog',
]),
'value' => $entry
->getData()['username'],
],
'client_ip' => [
'label' => t('User\'s I.P. address', [], [
'context' => 'module:jsonlog',
]),
'value' => $entry
->getData()['client_ip'],
],
'link' => [
'label' => t('Link (URL path or NULL)', [], [
'context' => 'module:jsonlog',
]),
'value' => $entry
->getData()['link'],
],
'code' => [
'label' => t('Code (positive integer if watchdog \'link\' is N or \'N\')', [], [
'context' => 'module:jsonlog',
]),
'value' => $entry
->getData()['code'],
],
'trunc' => [
'label' => t('Truncation (null, or array [original message length, truncated message length])', [], [
'context' => 'module:jsonlog',
]),
'value' => $entry
->getData()['trunc'],
],
];
$table_header = [
t('Property', [], [
'context' => 'module:jsonlog',
]),
t('JSON field name', [], [
'context' => 'module:jsonlog',
]),
t('Example', [], [
'context' => 'module:jsonlog',
]),
];
$table_rows = [];
foreach ($json_fields as $name => $props) {
$table_rows[] = [
'data' => [
$props['label'],
$name,
$props['value'] === NULL ? 'null' : $props['value'],
],
];
}
return [
'#header' => $table_header,
'#rows' => $table_rows,
];
}