function LoggerController::watchdogOverview in MongoDB 8
Display watchdogs entries in mongodb. @TODO Use theme function. Use exposed filter like dblog.
Return value
array a form array
File
- src/
Logger/ LoggerController.php, line 116 - Controller service for the MongoDB Watchdog reports.
Class
Namespace
Drupal\mongodb\LoggerCode
function watchdogOverview() {
$icons = array(
WATCHDOG_DEBUG => '',
WATCHDOG_INFO => '',
WATCHDOG_NOTICE => '',
WATCHDOG_WARNING => array(
'#theme' => 'image',
'path' => 'misc/watchdog-warning.png',
'alt' => t('warning'),
'title' => t('warning'),
),
WATCHDOG_ERROR => array(
'#theme' => 'image',
'path' => 'misc/watchdog-error.png',
'alt' => t('error'),
'title' => t('error'),
),
WATCHDOG_CRITICAL => array(
'#theme' => 'image',
'path' => 'misc/watchdog-error.png',
'alt' => t('critical'),
'title' => t('critical'),
),
WATCHDOG_ALERT => array(
'#theme' => 'image',
'path' => 'misc/watchdog-error.png',
'alt' => t('alert'),
'title' => t('alert'),
),
WATCHDOG_EMERGENCY => array(
'#theme' => 'image',
'path' => 'misc/watchdog-error.png',
'alt' => t('emergency'),
'title' => t('emergency'),
),
);
global $pager_page_array, $pager_total, $pager_total_items, $pager_limits;
$per_page = 50;
$page = isset($_GET['page']) ? $_GET['page'] : '';
$pager_page_array = explode(',', $page);
$on_page = $pager_page_array[0];
$cursor = $this->logger
->templatesCollection()
->find($this
->buildFilterQuery())
->limit($per_page)
->skip($on_page * $per_page)
->sort(array(
'timestamp' => -1,
));
$build['mongodb_watchdog_filter_form'] = $this->formBuilder
->getForm('Drupal\\mongodb\\Form\\LoggerClearForm');
$build['mongodb_watchdog_clear_log_form'] = $this->formBuilder
->getForm('Drupal\\mongodb\\Form\\LoggerFilterForm');
$header = array(
'',
// Icon column.
t('#'),
array(
'data' => t('Type'),
),
array(
'data' => t('Date'),
),
t('Source'),
t('Message'),
);
$rows = array();
foreach ($cursor as $id => $value) {
if ($value['type'] == 'php' && $value['message'] == '%type: %message in %function (line %line of %file).') {
$collection = $this->logger
->eventCollection($value['_id']);
$result = $collection
->find()
->sort(array(
'$natural' => -1,
))
->limit(1)
->getNext();
if ($value) {
$value['file'] = basename($result['variables']['%file']);
$value['line'] = $result['variables']['%line'];
$value['message'] = '%type in %function';
$value['variables'] = $result['variables'];
}
}
$message = truncate_utf8(strip_tags($this
->formatMessage($value)), 56, TRUE, TRUE);
$rows[$id] = array(
$icons[$value['severity']],
isset($value['count']) && $value['count'] > 1 ? $value['count'] : '',
t($value['type']),
empty($value['timestamp']) ? '' : format_date($value['timestamp'], 'short'),
empty($value['file']) ? '' : truncate_utf8(basename($value['file']), 30) . (empty($value['line']) ? '' : '+' . $value['line']),
l($message, "admin/reports/mongodb/{$id}"),
);
}
$build['mongodb_watchdog_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#attributes' => array(
'id' => 'admin-mongodb_watchdog',
),
);
// Add the pager.
if ($on_page > 0 || count($rows) >= $per_page) {
$pager_total_items[0] = $this->logger
->templatesCollection()
->count($this
->buildFilterQuery());
$pager_total[0] = ceil($pager_total_items[0] / $per_page);
$pager_page_array[0] = max(0, min((int) $pager_page_array[0], (int) $pager_total[0] - 1));
$pager_limits[0] = $per_page;
$build['pager'] = array(
'#theme' => 'pager',
);
}
return $build;
}