/[drupal]/drupal/modules/syslog/syslog.module
ViewVC logotype

Contents of /drupal/modules/syslog/syslog.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.27 - (show annotations) (download) (as text)
Fri Oct 23 22:24:18 2009 UTC (5 weeks, 1 day ago) by webchick
Branch: MAIN
Changes since 1.26: +2 -2 lines
File MIME type: text/x-php
#600974 by effulgentsia, JohnAlbin, sun, and Damien Tournoud: Allow theme functions to take one argument without any hacks. NOTE: This is an API change in hook_theme().
1 <?php
2 // $Id: syslog.module,v 1.26 2009/10/09 01:00:04 dries Exp $
3
4 /**
5 * @file
6 * Redirects logging messages to syslog.
7 */
8
9 if (defined('LOG_LOCAL0')) {
10 define('DEFAULT_SYSLOG_FACILITY', LOG_LOCAL0);
11 }
12 else {
13 define('DEFAULT_SYSLOG_FACILITY', LOG_USER);
14 }
15
16 /**
17 * Implement hook_help().
18 */
19 function syslog_help($path, $arg) {
20 switch ($path) {
21 case 'admin/help#syslog':
22 $output = '<p>' . t("Syslog logs events by sending messages to the logging facility of your web server's operating system. Syslog is an operating system administrative logging tool, and 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.") . '</p>';
23 $output .= '<h2>' . t('UNIX, Linux & Mac OS X') . '</h2>';
24 $output .= '<p>' . t('On UNIX, Linux and Mac OS X, the file /etc/syslog.conf defines this 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 <code>syslog.conf</code>, see the <a href="@syslog_conf"><code>syslog.conf</code> manual page</a>.', array('@syslog_conf' => url('http://www.rt.com/man/syslog.5.html'))) . '</p>';
25 $output .= '<h2>' . t('Microsoft Windows') . '</h2>';
26 $output .= '<p>' . t('On Microsoft Windows messages are always sent to the Event Log using the code <code>LOG_USER</code>.') . '</p>';
27 $output .= '<p>' . t('For more information, see the <a href="@syslog">online handbook</a> and 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' => url('http://www.php.net/manual/function.openlog.php'), '@php_syslog' => url('http://www.php.net/manual/function.syslog.php'))) . '</p>';
28
29 return $output;
30 }
31 }
32
33 /**
34 * Implement hook_form_FORM_ID_alter().
35 */
36 function syslog_form_system_logging_settings_alter(&$form, &$form_state) {
37 if (defined('LOG_LOCAL0')) {
38 $help = module_exists('help') ? ' ' . l(t('More information'), 'admin/help/syslog') . '.' : NULL;
39 $form['syslog_facility'] = array(
40 '#type' => 'select',
41 '#title' => t('Syslog facility'),
42 '#default_value' => variable_get('syslog_facility', LOG_LOCAL0),
43 '#options' => syslog_facility_list(),
44 '#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,
45 );
46 $form['buttons']['#weight'] = 1;
47 }
48 }
49
50 /**
51 * List all possible syslog facilities for UNIX/Linux.
52 *
53 * @return array
54 */
55 function syslog_facility_list() {
56 return array(
57 LOG_LOCAL0 => 'LOG_LOCAL0',
58 LOG_LOCAL1 => 'LOG_LOCAL1',
59 LOG_LOCAL2 => 'LOG_LOCAL2',
60 LOG_LOCAL3 => 'LOG_LOCAL3',
61 LOG_LOCAL4 => 'LOG_LOCAL4',
62 LOG_LOCAL5 => 'LOG_LOCAL5',
63 LOG_LOCAL6 => 'LOG_LOCAL6',
64 LOG_LOCAL7 => 'LOG_LOCAL7',
65 );
66 }
67
68 /**
69 * Implement hook_watchdog().
70 */
71 function syslog_watchdog(array $log_entry) {
72 $log_init = &drupal_static(__FUNCTION__, FALSE);
73
74 if (!$log_init) {
75 $log_init = TRUE;
76 $default_facility = defined('LOG_LOCAL0') ? LOG_LOCAL0 : LOG_USER;
77 openlog('drupal', LOG_NDELAY, variable_get('syslog_facility', $default_facility));
78 }
79
80 syslog($log_entry['severity'], theme('syslog_format', array('entry' => $log_entry)));
81 }
82
83 function syslog_theme() {
84 return array(
85 'syslog_format' => array(
86 'variables' => array('entry' => NULL),
87 ),
88 );
89 }
90
91 /**
92 * Format a system log entry.
93 *
94 * @ingroup themeable
95 */
96 function theme_syslog_format($variables) {
97 $entry = $variables['entry'];
98 global $base_url;
99
100 $message = $base_url;
101 $message .= '|' . $entry['timestamp'];
102 $message .= '|' . $entry['type'];
103 $message .= '|' . $entry['ip'];
104 $message .= '|' . $entry['request_uri'];
105 $message .= '|' . $entry['referer'];
106 $message .= '|' . $entry['user']->uid;
107 $message .= '|' . strip_tags($entry['link']);
108 $message .= '|' . strip_tags(is_null($entry['variables']) ? $entry['message'] : strtr($entry['message'], $entry['variables']));
109
110 return $message;
111 }

  ViewVC Help
Powered by ViewVC 1.1.2