You are here

errorlog.module in Logging and alerts 6.2

Sends logs and alerts to the web server's log.

File

errorlog/errorlog.module
View source
<?php

// Copyright 2007 Khalid Baheyeldin http://2bits.com

/**
 * @file
 * Sends logs and alerts to the web server's log.
 */

/**
 * Implementation of hook_help().
 */
function errorlog_help($path, $arg) {
  switch ($path) {
    case 'admin/help#errorlog':
    case 'admin/settings/logging/errorlog':
      return '<p>' . t("Sends logs and alerts to the web server's error log.") . '</p>';
  }
}

/**
 * Implementation of hook_menu().
 */
function errorlog_menu() {
  $items['admin/settings/logging/errorlog'] = array(
    'title' => 'Web server logging and alerts',
    'description' => 'Settings for error log logging and alerts.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'errorlog_admin_settings',
    ),
    'access arguments' => array(
      'administer site configuration',
    ),
    'file' => 'errorlog.admin.inc',
  );
  return $items;
}

/**
 * Implementation of hook_watchdog().
 */
function errorlog_watchdog($log) {
  global $user;
  if (variable_get('errorlog_' . $log['severity'], FALSE)) {
    $language = user_preferred_language($user);

    // Make sure that $log['variables'] is always an array to avoid
    // errors like in issue http://drupal.org/node/1325938
    if (!is_array($log['variables'])) {
      $log['variables'] = array();
    }

    // Send themed alert to the web server's log.
    $message = theme('errorlog_format', $log);
    error_log($message);
  }
}

/**
 * Implementation of hook_theme().
 */
function errorlog_theme() {
  return array(
    'errorlog_format' => array(
      'arguments' => array(
        'log_msg' => NULL,
      ),
    ),
  );
}
function theme_errorlog_format($log_msg = array()) {
  global $base_root;
  $message = $base_root;
  $message .= '|type=' . $log_msg['type'];
  $message .= '|ip=' . $log_msg['ip'];
  $message .= '|uri=' . $log_msg['request_uri'];
  $message .= '|referer=' . $log_msg['referer'];
  $message .= '|uid=' . $log_msg['user']->uid;
  $message .= '|link=' . strip_tags($log_msg['link']);
  $message .= '|message=' . strip_tags(is_null($log_msg['variables']) ? $log_msg['message'] : strtr($log_msg['message'], $log_msg['variables']));
  return $message;
}

Functions

Namesort descending Description
errorlog_help Implementation of hook_help().
errorlog_menu Implementation of hook_menu().
errorlog_theme Implementation of hook_theme().
errorlog_watchdog Implementation of hook_watchdog().
theme_errorlog_format