You are here

function nodejs_watchdog_watchdog in Node.js integration 7

Implements hook_watchdog().

File

nodejs_watchdog/nodejs_watchdog.module, line 14

Code

function nodejs_watchdog_watchdog(array $entry) {
  $classes = array(
    WATCHDOG_DEBUG => 'dblog-debug',
    WATCHDOG_INFO => 'dblog-info',
    WATCHDOG_NOTICE => 'dblog-notice',
    WATCHDOG_WARNING => 'dblog-warning',
    WATCHDOG_ERROR => 'dblog-error',
    WATCHDOG_CRITICAL => 'dblog-critical',
    WATCHDOG_ALERT => 'dblog-alert',
    WATCHDOG_EMERGENCY => 'dblog-emerg',
  );
  $entry['variables'] = isset($entry['variables']) ? serialize($entry['variables']) : serialize(array());
  if (module_exists('dblog')) {

    /**
     * We can get wid because hook_watchdog for module nodejs_watchdog called after this hook for module dblog.
     */
    $query = db_select('watchdog', 'wd')
      ->fields('wd', array(
      'wid',
    ))
      ->condition('uid', $entry['uid'])
      ->condition('type', $entry['type'])
      ->condition('message', $entry['message'])
      ->condition('hostname', $entry['ip'])
      ->condition('timestamp', $entry['timestamp'])
      ->execute()
      ->fetchAssoc();
    if (isset($query['wid'])) {
      $entry['wid'] = $query['wid'];
    }
  }
  $row = array(
    'data' => array(
      array(
        'class' => 'icon',
      ),
      t($entry['type']),
      format_date($entry['timestamp'], 'short'),
      theme('dblog_message', array(
        'event' => (object) $entry,
        'link' => TRUE,
      )),
      theme('username', array(
        'account' => $entry['user'],
      )),
      $entry['link'],
    ),
    'class' => array(
      drupal_html_class('dblog-' . $entry['type']),
      $classes[$entry['severity']],
    ),
  );
  $commands[] = ajax_command_before('#admin-dblog tr:eq(1)', nodejs_watchdog_theme_row($row));
  $message = (object) array(
    'channel' => 'watchdog_dblog',
    'commands' => $commands,
    'callback' => 'nodejsWatchdog',
  );
  nodejs_send_content_channel_message($message);
}