134 lines
5.0 KiB
Plaintext
134 lines
5.0 KiB
Plaintext
<?php
|
|
// $Id$
|
|
|
|
/**
|
|
* @file
|
|
* Redirects logging messages to syslog.
|
|
*/
|
|
|
|
if (defined('LOG_LOCAL0')) {
|
|
define('DEFAULT_SYSLOG_FACILITY', LOG_LOCAL0);
|
|
}
|
|
else {
|
|
define('DEFAULT_SYSLOG_FACILITY', LOG_USER);
|
|
}
|
|
|
|
/**
|
|
* Implements hook_help().
|
|
*/
|
|
function syslog_help($path, $arg) {
|
|
switch ($path) {
|
|
case 'admin/help#syslog':
|
|
$output = '';
|
|
$output .= '<h3>' . t('About') . '</h3>';
|
|
$output .= '<p>' . t("The Syslog module logs events by sending messages to the logging facility of your web server's operating system. Syslog is an operating system administrative logging tool that provides valuable information for use in system management and security auditing. Most suited to medium and large sites, Syslog provides filtering tools that allow messages to be routed by type and severity. For more information, see the online handbook entry for <a href='@syslog'>Syslog module</a> and PHP's <a href='@php_openlog'>openlog</a> and <a href='@php_syslog'>syslog</a> functions.", array('@syslog' => 'http://drupal.org/handbook/modules/syslog', '@php_openlog' => 'http://www.php.net/manual/function.openlog.php', '@php_syslog' => 'http://www.php.net/manual/function.syslog.php')) . '</p>';
|
|
$output .= '<h3>' . t('Uses') . '</h3>';
|
|
$output .= '<dl>';
|
|
$output .= '<dt>' . t('Logging for UNIX, Linux, and Mac OS X') . '</dt>';
|
|
$output .= '<dd>' . t('On UNIX, Linux, and Mac OS X, the file <em>/etc/syslog.conf</em> defines the routing configuration. Messages can be flagged with the codes <code>LOG_LOCAL0</code> through <code>LOG_LOCAL7</code>. For information on Syslog facilities, severity levels, and how to set up <em>syslog.conf</em>, see the <em>syslog.conf</em> manual page on your command line.') . '</dd>';
|
|
$output .= '<dt>' . t('Logging for Microsoft Windows') . '</dt>';
|
|
$output .= '<dd>' . t('On Microsoft Windows, messages are always sent to the Event Log using the code <code>LOG_USER</code>.') . '</dd>';
|
|
$output .= '</dl>';
|
|
return $output;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implements hook_form_FORM_ID_alter().
|
|
*/
|
|
function syslog_form_system_logging_settings_alter(&$form, &$form_state) {
|
|
if (defined('LOG_LOCAL0')) {
|
|
$help = module_exists('help') ? ' ' . l(t('More information'), 'admin/help/syslog') . '.' : NULL;
|
|
$form['syslog_facility'] = array(
|
|
'#type' => 'select',
|
|
'#title' => t('Syslog facility'),
|
|
'#default_value' => variable_get('syslog_facility', LOG_LOCAL0),
|
|
'#options' => syslog_facility_list(),
|
|
'#description' => t('Depending on the system configuration, Syslog and other logging tools use this code to identify or filter messages from within the entire system log.') . $help,
|
|
);
|
|
$form['actions']['#weight'] = 1;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* List all possible syslog facilities for UNIX/Linux.
|
|
*
|
|
* @return array
|
|
*/
|
|
function syslog_facility_list() {
|
|
return array(
|
|
LOG_LOCAL0 => 'LOG_LOCAL0',
|
|
LOG_LOCAL1 => 'LOG_LOCAL1',
|
|
LOG_LOCAL2 => 'LOG_LOCAL2',
|
|
LOG_LOCAL3 => 'LOG_LOCAL3',
|
|
LOG_LOCAL4 => 'LOG_LOCAL4',
|
|
LOG_LOCAL5 => 'LOG_LOCAL5',
|
|
LOG_LOCAL6 => 'LOG_LOCAL6',
|
|
LOG_LOCAL7 => 'LOG_LOCAL7',
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Implements hook_watchdog().
|
|
*/
|
|
function syslog_watchdog(array $log_entry) {
|
|
$log_init = &drupal_static(__FUNCTION__, FALSE);
|
|
|
|
if (!$log_init) {
|
|
$log_init = TRUE;
|
|
$default_facility = defined('LOG_LOCAL0') ? LOG_LOCAL0 : LOG_USER;
|
|
openlog('drupal', LOG_NDELAY, variable_get('syslog_facility', $default_facility));
|
|
}
|
|
|
|
syslog($log_entry['severity'], theme('syslog_format', array('entry' => $log_entry)));
|
|
}
|
|
|
|
/**
|
|
* Implements hook_theme().
|
|
*/
|
|
function syslog_theme() {
|
|
return array(
|
|
'syslog_format' => array(
|
|
'variables' => array('entry' => NULL),
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Returns a string for a system log entry.
|
|
*
|
|
* @param $variables
|
|
* An associative array containing:
|
|
* - entry: An array containing the data about the log entry, containing:
|
|
* - timestamp: The date and time of the log entry.
|
|
* - type: The type of log entry.
|
|
* - ip: The IP address.
|
|
* - request_uri: The requested URI.
|
|
* - referer: The URL which referred to the request URI.
|
|
* - user: The user object associated with the log entry.
|
|
* - link: A link accociated with the log entry.
|
|
* - variables: A string representing the data to log.
|
|
* - message: If variables is not specified, a string for the log message.
|
|
*
|
|
* @return
|
|
* A string containing a pipe-delimited "|" log message.
|
|
*
|
|
* @ingroup themeable
|
|
*/
|
|
function theme_syslog_format($variables) {
|
|
$entry = $variables['entry'];
|
|
global $base_url;
|
|
|
|
$message = $base_url;
|
|
$message .= '|' . $entry['timestamp'];
|
|
$message .= '|' . $entry['type'];
|
|
$message .= '|' . $entry['ip'];
|
|
$message .= '|' . $entry['request_uri'];
|
|
$message .= '|' . $entry['referer'];
|
|
$message .= '|' . $entry['user']->uid;
|
|
$message .= '|' . strip_tags($entry['link']);
|
|
$message .= '|' . strip_tags(is_null($entry['variables']) ? $entry['message'] : strtr($entry['message'], $entry['variables']));
|
|
|
|
return $message;
|
|
}
|