function mongodb_watchdog_event in MongoDB 7
Same name and namespace in other branches
- 6 mongodb_watchdog/mongodb_watchdog.admin.inc \mongodb_watchdog_event()
Display watchdogs entry details in MongoDB.
Parameters
array $dblog: A log event in array format.
1 string reference to 'mongodb_watchdog_event'
- mongodb_watchdog_menu in mongodb_watchdog/
mongodb_watchdog.module - Implements hook_menu().
File
- mongodb_watchdog/
mongodb_watchdog.admin.inc, line 146 - Settings for mongodb. Moved back to module file.
Code
function mongodb_watchdog_event(array $dblog) {
$severity = watchdog_severity_levels();
$rows = array(
array(
array(
'data' => t('Type'),
'header' => TRUE,
),
// phpcs:ignore
t($dblog['type']),
),
array(
array(
'data' => t('Severity'),
'header' => TRUE,
),
$severity[$dblog['severity']],
),
array(
array(
'data' => t('Function'),
'header' => TRUE,
),
isset($dblog['function']) ? $dblog['function'] : '',
),
array(
array(
'data' => t('File'),
'header' => TRUE,
),
isset($dblog['file']) ? $dblog['file'] : '',
),
array(
array(
'data' => t('Line'),
'header' => TRUE,
),
isset($dblog['line']) ? $dblog['line'] : '',
),
array(
array(
'data' => t('Count'),
'header' => TRUE,
),
isset($dblog['count']) ? $dblog['count'] : '',
),
);
$build['reports'] = array(
'#type' => 'markup',
'#markup' => l(t('Return to log report'), 'admin/reports/mongodb'),
);
$build['mongodb_watchdog_event_table']['header'] = array(
'#theme' => 'table',
'#rows' => $rows,
'#attributes' => array(
'class' => array(
'dblog-event',
),
),
);
// @todo: the count is unreliable, so just get the actual number of entries.
// $items_limit = variable_get('mongodb_watchdog_items', 10000);
// $total = min($dblog['count'], $items_limit);
$collection = mongodb_collection(variable_get('mongodb_watchdog', 'watchdog'));
$collection = $collection->db
->selectCollection('watchdog_event_' . $dblog['_id']);
$total = $collection
->count();
$limit = 20;
$pagenumber = mongodb_watchdog_pager_init(0, $limit, $total);
$result = $collection
->find()
->skip($pagenumber * $limit)
->limit($limit)
->sort(array(
'$natural' => -1,
));
$severity = watchdog_severity_levels();
$rows = array();
$header = array(
array(
'data' => t('Date'),
'header' => TRUE,
),
array(
'data' => t('User'),
'header' => TRUE,
),
array(
'data' => t('Location'),
'header' => TRUE,
),
array(
'data' => t('Referrer'),
'header' => TRUE,
),
array(
'data' => t('Hostname'),
'header' => TRUE,
),
array(
'data' => t('Message'),
'header' => TRUE,
),
array(
'data' => t('Operations'),
'header' => TRUE,
),
);
foreach ($result as $event) {
if (isset($event['wd-user'])) {
$account = $event['wd-user'];
unset($event['wd-user']);
$ip = $dblog['ip'];
$request_uri = $dblog['request_uri'];
$referer = $dblog['referer'];
$link = $dblog['link'];
$dblog['variables'] = $event;
}
else {
$account = $event['user'];
$ip = $event['ip'];
$request_uri = $event['request_uri'];
$referer = $event['referer'];
$link = $event['link'];
$dblog['variables'] = $event['variables'];
}
$rows[] = array(
format_date($event['timestamp'], 'short'),
l($account['name'], 'user/' . $account['uid']),
$request_uri ? l(truncate_utf8(basename($request_uri), 20), $request_uri) : '',
$referer ? l(truncate_utf8(basename($referer), 20), $referer) : '',
check_plain($ip),
_mongodb_watchdog_format_message($dblog),
$link,
);
}
$build['mongodb_watchdog_event_table']['messages'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
);
if ($total > $limit) {
$build['mongodb_watchdog_event_table']['pager'] = array(
'#theme' => 'pager',
);
}
return $build;
}