- Patch #223298 by Dave Reid: change {dblog}.type VARCHAR limit from 16 to 64.

merge-requests/26/head
Dries Buytaert 2008-12-28 20:41:19 +00:00
parent 1d14b0f894
commit 5bbad8a4dc
5 changed files with 69 additions and 50 deletions

View File

@ -887,6 +887,7 @@ function request_uri() {
* A link to associate with the message.
*
* @see watchdog_severity_levels()
* @see hook_watchdog()
*/
function watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) {
global $user, $base_root;
@ -899,7 +900,7 @@ function watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NO
$in_error_state = TRUE;
// Prepare the fields to be logged
$log_message = array(
$log_entry = array(
'type' => $type,
'message' => $message,
'variables' => $variables,
@ -914,7 +915,7 @@ function watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NO
// Call the logging hooks to log/process the message
foreach (module_implements('watchdog', TRUE) as $module) {
module_invoke($module, 'watchdog', $log_message);
module_invoke($module, 'watchdog', $log_entry);
}
// It is critical that the semaphore is only cleared here, in the parent

View File

@ -37,7 +37,7 @@ function dblog_schema() {
),
'type' => array(
'type' => 'varchar',
'length' => 16,
'length' => 64,
'not null' => TRUE,
'default' => '',
'description' => 'Type of log message, for example "user" or "page not found."',
@ -121,3 +121,12 @@ function dblog_update_7002() {
db_add_index($ret, 'watchdog', 'uid', array('uid'));
return $ret;
}
/**
* Allow longer type values.
*/
function dblog_update_7003() {
$ret = array();
db_change_field($ret, 'watchdog', 'type', 'type', array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => ''));
return $ret;
}

View File

@ -118,19 +118,24 @@ function _dblog_get_message_types() {
return $types;
}
function dblog_watchdog($log = array()) {
/**
* Implementation of hook_watchdog().
*
* Note some values may be truncated for database column size restrictions.
*/
function dblog_watchdog(array $log_entry) {
Database::getConnection('default')->insert('watchdog')
->fields(array(
'uid' => $log['user']->uid,
'type' => $log['type'],
'message' => $log['message'],
'variables' => serialize($log['variables']),
'severity' => $log['severity'],
'link' => $log['link'],
'location' => $log['request_uri'],
'referer' => $log['referer'],
'hostname' => $log['ip'],
'timestamp' => $log['timestamp'],
'uid' => $log_entry['user']->uid,
'type' => substr($log_entry['type'], 0, 64),
'message' => $log_entry['message'],
'variables' => serialize($log_entry['variables']),
'severity' => $log_entry['severity'],
'link' => substr($log_entry['link'], 0, 255),
'location' => $log_entry['request_uri'],
'referer' => $log_entry['referer'],
'hostname' => substr($log_entry['ip'], 0, 128),
'timestamp' => $log_entry['timestamp'],
))
->execute();
}
@ -148,4 +153,3 @@ function theme_dblog_filters($form) {
$output .= '<div id="dblog-admin-buttons">' . drupal_render($form['buttons']) . '</div>';
return $output;
}

View File

@ -68,7 +68,10 @@ function syslog_facility_list() {
return $facility_list;
}
function syslog_watchdog($entry) {
/**
* Implementation of hook_watchdog().
*/
function syslog_watchdog(array $log_entry) {
static $log_init = FALSE;
if (!$log_init) {
@ -76,7 +79,7 @@ function syslog_watchdog($entry) {
openlog('drupal', LOG_NDELAY, variable_get('syslog_facility', DEFAULT_SYSLOG_FACILITY));
}
syslog($entry['severity'], theme('syslog_format', $entry));
syslog($log_entry['severity'], theme('syslog_format', $log_entry));
}
function syslog_theme() {

View File

@ -683,7 +683,7 @@ function hook_xmlrpc() {
* SMS, Email, pager, syslog, ...etc.
*
* @param $log_entry
* The log_entry is an associative array containing the following keys:
* An associative array containing the following keys:
* - type: The type of message for this entry. For contributed modules, this is
* normally the module name. Do not use 'debug', use severity WATCHDOG_DEBUG instead.
* - user: The user object for the user who was logged in when the event happened.
@ -706,8 +706,8 @@ function hook_xmlrpc() {
* @return
* None.
*/
function hook_watchdog($log_msg) {
global $base_url;
function hook_watchdog(array $log_entry) {
global $base_url, $language;
$severity_list = array(
WATCHDOG_EMERG => t('Emergency'),
@ -720,38 +720,40 @@ function hook_watchdog($log_msg) {
WATCHDOG_DEBUG => t('Debug'),
);
$to = "someone@example.com";
$subject = t('[@site_name] @severity_desc: Alert from your web site', array(
'@site_name' => variable_get('site_name', 'Drupal'),
'@severity_desc' => $severity_list[$log['severity']]));
$message = "\nSite: @base_url";
$message .= "\nSeverity: (@severity) @severity_desc";
$message .= "\nTimestamp: @timestamp";
$message .= "\nType: @type";
$message .= "\nIP Address: @ip";
$message .= "\nRequest URI: @request_uri";
$message .= "\nReferrer URI: @referer_uri";
$message .= "\nUser: (@uid) @name";
$message .= "\nLink: @link";
$message .= "\nMessage: \n\n@message";
$message = t($message, array(
'@base_url' => $base_url,
'@severity' => $log_msg['severity'],
'@severity_desc' => $severity_list[$log_msg['severity']],
'@timestamp' => format_date($log_msg['timestamp']),
'@type' => $log_msg['type'],
'@ip' => $log_msg['ip'],
'@request_uri' => $log_msg['request_uri'],
'@referer_uri' => $log_msg['referer'],
'@uid' => $log_msg['user']->uid,
'@name' => $log_msg['user']->name,
'@link' => strip_tags($log_msg['link']),
'@message' => strip_tags($log_msg['message']),
$to = 'someone@example.com';
$params = array();
$params['subject'] = t('[@site_name] @severity_desc: Alert from your web site', array(
'@site_name' => variable_get('site_name', 'Drupal'),
'@severity_desc' => $severity_list[$log_entry['severity']],
));
drupal_mail('emaillog', $to, $subject, $body, $from = NULL, $headers = array());
$params['message'] = "\nSite: @base_url";
$params['message'] .= "\nSeverity: (@severity) @severity_desc";
$params['message'] .= "\nTimestamp: @timestamp";
$params['message'] .= "\nType: @type";
$params['message'] .= "\nIP Address: @ip";
$params['message'] .= "\nRequest URI: @request_uri";
$params['message'] .= "\nReferrer URI: @referer_uri";
$params['message'] .= "\nUser: (@uid) @name";
$params['message'] .= "\nLink: @link";
$params['message'] .= "\nMessage: \n\n@message";
$params['message'] = t($params['message'], array(
'@base_url' => $base_url,
'@severity' => $log_entry['severity'],
'@severity_desc' => $severity_list[$log_entry['severity']],
'@timestamp' => format_date($log_entry['timestamp']),
'@type' => $log_entry['type'],
'@ip' => $log_entry['ip'],
'@request_uri' => $log_entry['request_uri'],
'@referer_uri' => $log_entry['referer'],
'@uid' => $log_entry['user']->uid,
'@name' => $log_entry['user']->name,
'@link' => strip_tags($log_entry['link']),
'@message' => strip_tags($log_entry['message']),
));
drupal_mail('emaillog', 'entry', $to, $language, $params);
}
/**