You are here

function mongodb_watchdog_event in MongoDB 6

Same name and namespace in other branches
  1. 7 mongodb_watchdog/mongodb_watchdog.admin.inc \mongodb_watchdog_event()

Display watchdogs entry details in MongoDB.

Parameters

array $dblog: A log entry in array form.

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 120
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,
      ),
      // The entry type comes from code as the first parameter to a watchdog()
      // call and is not a dynamic string, so it is ok to pass to t().
      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 = theme('table', NULL, $rows, array(
    'class' => 'dblog-event',
  ));

  // The count is unreliable, so just get the actual number of entries.
  $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(
      // Build the user account page link, instead of theme('username'),
      // theme('username') do not retrieve links to disabled accounts page.
      format_date($event['timestamp'], 'small'),
      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 .= theme('table', $header, $rows);
  if ($total > $limit) {
    $build .= theme('pager');
  }
  return $build;
}