Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http://drupal.org/node/659784 #40

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 22 additions & 31 deletions modules/syslog/syslog.module
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ function syslog_admin_settings() {
'#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(
'@syslog_help' => url('admin/help/syslog'))),
);

$form['syslog_format'] = array(
'#type' => 'textarea',
'#title' => t('Syslog format'),
'#default_value' => variable_get('syslog_format', '!base_url|!timestamp|!type|!ip|!request_uri|!referer|!uid|!link|!message'),
'#description' => t('Specify the format of the syslog entry. Available variables are: <dl><dt><code>!base_url</code></dt><dd>Base URL of the site.</dd><dt><code>!timestamp</code></dt><dd>Unix timestamp of the log entry.</dd><dt><code>!type</code></dt><dd>The category to which this message belongs.</dd><dt><code>!ip</code></dt><dd>IP address of the user triggering the message.</dd><dt><code>!request_uri</code></dt><dd>The requested URI.</dd><dt><code>!referer</code></dt><dd>HTTP Referer if available.</dd><dt><code>!uid</code></dt><dd>User ID.</dd><dt><code>!link</code></dt><dd>A link to associate with the message.</dd><dt><code>!message</code></dt><dd>The message to store in the log.</dd></dl>'),
);
return system_settings_form($form);
}

Expand All @@ -74,42 +81,26 @@ function syslog_facility_list() {
return $facility_list;
}

function syslog_watchdog($entry) {
function syslog_watchdog(array $log_entry) {
global $base_url;
static $log_init = FALSE;

if (!$log_init) {
$log_init = TRUE;
openlog(variable_get('syslog_identity', 'drupal'), LOG_NDELAY, variable_get('syslog_facility', DEFAULT_SYSLOG_FACILITY));
}

syslog($entry['severity'], theme('syslog_format', $entry));
}

function syslog_theme() {
return array(
'syslog_format' => array(
'arguments' => array('entry' => NULL),
),
);
}
$message = strtr(variable_get('syslog_format', '!base_url|!timestamp|!type|!ip|!request_uri|!referer|!uid|!link|!message'), array(
'!base_url' => $base_url,
'!timestamp' => $log_entry['timestamp'],
'!type' => $log_entry['type'],
'!ip' => $log_entry['ip'],
'!request_uri' => $log_entry['request_uri'],
'!referer' => $log_entry['referer'],
'!uid' => $log_entry['user']->uid,
'!link' => strip_tags($log_entry['link']),
'!message' => strip_tags(is_null($log_entry['variables']) ? $log_entry['message'] : strtr($log_entry['message'], $log_entry['variables'])),
));

/**
* Format a system log entry.
*
* @ingroup themeable
*/
function theme_syslog_format($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;
}
syslog($log_entry['severity'], $message);
}