Code coverage for /20080809/modules/syslog/syslog.module

Line #Times calledCode
1
<?php
2
// $Id: syslog.module,v 1.17 2008/07/24 06:52:35 dries Exp $
3
4
/**
5
 * @file
6
 * Redirects logging messages to syslog.
7
 */
8
99
if (defined('LOG_LOCAL0')) {
109
  define('DEFAULT_SYSLOG_FACILITY', LOG_LOCAL0);
119
}
12
else {
13
  define('DEFAULT_SYSLOG_FACILITY', LOG_USER);
14
}
15
16
/**
17
 * Implementation of hook_help().
18
 */
199
function syslog_help($path, $arg) {
20
  switch ($path) {
216
    case 'admin/help#syslog':
220
      $output = '<p>' . t("The syslog module enables Drupal to send
messages to the operating system's logging facility.") . '</p>';
230
      $output .= '<p>' . t('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. On UNIX/Linux systems, the file /etc/syslog.conf defines this
routing configuration; on Microsoft Windows, all messages are sent to the
Event Log. For more information on syslog facilities, severity levels, and
how to set up a syslog.conf file, see <a href="@syslog_conf">UNIX/Linux
syslog.conf</a> and PHP\'s <a href="@php_openlog">openlog</a> and <a
href="@php_syslog">syslog</a> functions.', array('@syslog_conf' =>
url('http://www.rt.com/man/syslog.5.html'), '@php_openlog' =>
url('http://www.php.net/manual/en/function.openlog.php'), '@php_syslog' =>
url('http://www.php.net/manual/en/function.syslog.php'))) . '</p>';
240
      $output .= '<p>' . t('For more information, see the online handbook
entry for <a href="@syslog">Syslog module</a>.', array('@syslog' =>
'http://drupal.org/handbook/modules/syslog')) . '</p>';
250
      return $output;
260
  }
276
}
28
299
function syslog_menu() {
301
  $items['admin/settings/logging/syslog'] = array(
311
    'title'          => 'Syslog',
321
    'description'    => 'Settings for syslog logging. Syslog is an
operating system administrative logging tool used in systems 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.',
331
    'page callback'  => 'drupal_get_form',
341
    'page arguments' => array('syslog_admin_settings'),
351
    'access arguments' => array('administer site configuration'),
36
  );
371
  return $items;
380
}
39
409
function syslog_admin_settings() {
414
  $form['syslog_facility'] = array(
424
    '#type'          => 'select',
434
    '#title'         => t('Send events to this syslog facility'),
444
    '#default_value' => variable_get('syslog_facility',
DEFAULT_SYSLOG_FACILITY),
454
    '#options'       => syslog_facility_list(),
464
    '#description'   => t('Select the syslog facility code under which
Drupal\'s messages should be sent. On UNIX/Linux systems, Drupal can flag
its messages with the code LOG_LOCAL0 through LOG_LOCAL7; for Microsoft
Windows, all messages are flagged with the code LOG_USER. Depending on the
system configuration, syslog and other logging tools use this code to
identify or filter Drupal messages from within the entire system log. For
more information on syslog, see <a href="@syslog_help">Syslog help</a>.',
array(
474
      '@syslog_help' => url('admin/help/syslog'))),
48
  );
494
  return system_settings_form($form);
500
}
51
529
function syslog_facility_list() {
53
  $facility_list = array(
544
    LOG_USER   => t('LOG_USER - User level messages. Use this for
Windows.'),
554
  );
564
  if (defined('LOG_LOCAL0')) {
57
    $facility_list += array(
584
      LOG_LOCAL0 => t('LOG_LOCAL0 - Local 0'),
594
      LOG_LOCAL1 => t('LOG_LOCAL1 - Local 1'),
604
      LOG_LOCAL2 => t('LOG_LOCAL2 - Local 2'),
614
      LOG_LOCAL3 => t('LOG_LOCAL3 - Local 3'),
624
      LOG_LOCAL4 => t('LOG_LOCAL4 - Local 4'),
634
      LOG_LOCAL5 => t('LOG_LOCAL5 - Local 5'),
644
      LOG_LOCAL6 => t('LOG_LOCAL6 - Local 6'),
654
      LOG_LOCAL7 => t('LOG_LOCAL7 - Local 7'),
660
    );
674
  }
684
  return $facility_list;
690
}
70
719
function syslog_watchdog($entry) {
722
  static $log_init = FALSE;
73
742
  if (!$log_init) {
752
    $log_init = TRUE;
762
    openlog('drupal', LOG_NDELAY, variable_get('syslog_facility',
DEFAULT_SYSLOG_FACILITY));
772
  }
78
792
  syslog($entry['severity'], theme('syslog_format', $entry));
802
}
81
829
function syslog_theme() {
83
  return array(
84
    'syslog_format' => array(
852
      'arguments' => array('entry' => NULL),
862
    ),
872
  );
880
}
89
90
/**
91
 * Format a system log entry.
92
 *
93
 * @ingroup themeable
94
 */
959
function theme_syslog_format($entry) {
961
  global $base_url;
97
981
  $message  = $base_url;
991
  $message .= '|' . $entry['timestamp'];
1001
  $message .= '|' . $entry['type'];
1011
  $message .= '|' . $entry['ip'];
1021
  $message .= '|' . $entry['request_uri'];
1031
  $message .= '|' . $entry['referer'];
1041
  $message .= '|' . $entry['user']->uid;
1051
  $message .= '|' . strip_tags($entry['link']);
1061
  $message .= '|' . strip_tags(is_null($entry['variables']) ?
$entry['message'] : strtr($entry['message'], $entry['variables']));
107
1081
  return $message;
1090
}
1109