- Patch #13260 by UnConeD: watchdog module improvements.

We added a 'severity' column to watchdog():
    watchdog($type, $message, $link) --> watchdog($type, $message, $severity, $link);

    * Specify a severity in case you are reporting a warning or error.
    * The $link-parameter is now the fourth parameter instead of the third.

  TODO: document this in the upgrade guide.
4.6.x
Dries Buytaert 2005-01-09 09:22:40 +00:00
parent 0830efe9a6
commit 64b100d19a
29 changed files with 143 additions and 96 deletions

View File

@ -16,7 +16,7 @@ if (!ini_get('safe_mode')) {
// Check if the last cron run completed
if (variable_get('cron_busy', false)) {
watchdog('cron', t('Last cron run did not complete.'));
watchdog('cron', t('Last cron run did not complete.'), WATCHDOG_WARNING);
}
else {
variable_set('cron_busy', true);

View File

@ -750,6 +750,7 @@ CREATE TABLE watchdog (
uid integer NOT NULL default '0',
type varchar(16) NOT NULL default '',
message text NOT NULL default '',
severity smallint NOT NULL default '0',
link varchar(255) NOT NULL default '',
location varchar(128) NOT NULL default '',
hostname varchar(128) NOT NULL default '',

View File

@ -90,7 +90,8 @@ $sql_updates = array(
"2004-11-07" => "update_111",
"2004-11-15" => "update_112",
"2004-11-28" => "update_113",
"2004-12-05" => "update_114"
"2004-12-05" => "update_114",
"2005-01-07" => "update_115"
);
function update_32() {
@ -2066,6 +2067,17 @@ function update_114() {
return $ret;
}
function update_115() {
$ret = array();
if ($GLOBALS['db_type'] == 'mysql') {
$ret[] = update_sql("ALTER TABLE {watchdog} ADD severity tinyint(3) unsigned NOT NULL default '0'");
}
else if ($GLOBALS['db_type'] == 'pgsql') {
$ret[] = update_sql("ALTER TABLE {watchdog} ADD severity smallint NOT NULL default '0'");
}
return $ret;
}
function update_sql($sql) {
$edit = $_POST["edit"];
$result = db_query($sql);

View File

@ -9,6 +9,11 @@
define('CACHE_PERMANENT', 0);
define('CACHE_TEMPORARY', -1);
define('WATCHDOG_NOTICE', 0);
define('WATCHDOG_WARNING', 1);
define('WATCHDOG_ERROR', 2);
/**
* Locate the appropriate configuration file.
*
@ -574,12 +579,17 @@ function timer_start() {
* The category to which this message belongs.
* @param $message
* The message to store in the log.
* @param $severity
* The severity of the message. One of the following values:
* - WATCHDOG_NOTICE
* - WATCHDOG_WARNING
* - WATCHDOG_ERROR
* @param $link
* A link to associate with the message.
*/
function watchdog($type, $message, $link = NULL) {
function watchdog($type, $message, $severity = WATCHDOG_NOTICE, $link = NULL) {
global $user;
db_query("INSERT INTO {watchdog} (uid, type, message, link, location, hostname, timestamp) VALUES (%d, '%s', '%s', '%s', '%s', '%s', %d)", $user->uid, $type, $message, $link, request_uri(), $_SERVER['REMOTE_ADDR'], time());
db_query("INSERT INTO {watchdog} (uid, type, message, severity, link, location, hostname, timestamp) VALUES (%d, '%s', '%s', %d, '%s', '%s', '%s', %d)", $user->uid, $type, $message, $severity, $link, request_uri(), $_SERVER['REMOTE_ADDR'], time());
}
/**

View File

@ -166,7 +166,7 @@ function drupal_goto($path = '', $query = NULL, $fragment = NULL) {
*/
function drupal_not_found() {
header('HTTP/1.0 404 Not Found');
watchdog('page not found', t('%page not found.', array('%page' => '<em>'. db_escape_string($_GET['q']) .'</em>')));
watchdog('page not found', t('%page not found.', array('%page' => '<em>'. db_escape_string($_GET['q']) .'</em>')), WATCHDOG_WARNING);
$path = drupal_get_normal_path(variable_get('site_404', ''));
$status = MENU_NOT_FOUND;
@ -186,7 +186,7 @@ function drupal_not_found() {
*/
function drupal_access_denied() {
header('HTTP/1.0 403 Forbidden');
watchdog('access denied', t('%page denied access.', array('%page' => '<em>'. db_escape_string($_GET['q']) .'</em>')));
watchdog('access denied', t('%page denied access.', array('%page' => '<em>'. db_escape_string($_GET['q']) .'</em>')), WATCHDOG_WARNING);
$path = drupal_get_normal_path(variable_get('site_403', ''));
$status = MENU_NOT_FOUND;
@ -342,11 +342,11 @@ function error_handler($errno, $message, $filename, $line, $variables) {
$types = array(1 => 'error', 2 => 'warning', 4 => 'parse error', 8 => 'notice', 16 => 'core error', 32 => 'core warning', 64 => 'compile error', 128 => 'compile warning', 256 => 'user error', 512 => 'user warning', 1024 => 'user notice', 2048 => 'strict warning');
$entry = $types[$errno] .': '. $message .' in '. $filename .' on line '. $line .'.';
watchdog('error', t('%message in %file on line %line.', array('%error' => $types[$errno], '%message' => $message, '%file' => $filename, '%line' => $line)));
if (variable_get('error_level', 1) == 1) {
print '<pre>'. $entry .'</pre>';
}
watchdog('php', t('%message in %file on line %line.', array('%error' => $types[$errno], '%message' => $message, '%file' => $filename, '%line' => $line)), WATCHDOG_ERROR);
}
}
@ -602,7 +602,7 @@ function valid_input_data($data) {
$match += preg_match("/<\s*(applet|script|object|style|embed|form|blink|meta|html|frame|iframe|layer|ilayer|head|frameset|xml)/i", $data);
if ($match) {
watchdog('warning', t('Terminated request because of suspicious input data: %data.', array('%data' => '<em>'. drupal_specialchars($data) .'</em>')));
watchdog('security', t('Terminated request because of suspicious input data: %data.', array('%data' => '<em>'. drupal_specialchars($data) .'</em>')));
return FALSE;
}
}
@ -1597,7 +1597,7 @@ function drupal_xml_parser_create(&$data) {
$out = @recode_string($encoding . '..utf-8', $data);
}
else {
watchdog('warning', t("Unsupported XML encoding '%s'. Please install iconv, GNU recode or mbstring for PHP.", $encoding));
watchdog('php', t("Unsupported XML encoding '%s'. Please install iconv, GNU recode or mbstring for PHP.", $encoding), WATCHDOG_ERROR);
return 0;
}
@ -1606,7 +1606,7 @@ function drupal_xml_parser_create(&$data) {
$encoding = 'utf-8';
}
else {
watchdog('warning', t("Could not convert XML encoding '%s' to UTF-8.", $encoding));
watchdog('php', t("Could not convert XML encoding '%s' to UTF-8.", $encoding), WATCHDOG_WARNING);
return 0;
}
}

View File

@ -358,7 +358,7 @@ function file_save_upload($source, $dest = 0, $replace = FILE_EXISTS_RENAME) {
}
if (!user_access('bypass input data check') && !valid_input_data($file)) {
watchdog('error', t('Possible exploit abuse: invalid data.'));
watchdog('security', t('Possible exploit abuse: invalid data.'), WATCHDOG_WARNING);
drupal_set_message(t('File upload failed: invalid data.'), 'error');
return 0;
}
@ -402,7 +402,7 @@ function file_save_upload($source, $dest = 0, $replace = FILE_EXISTS_RENAME) {
*/
function file_save_data($data, $dest, $replace = FILE_EXISTS_RENAME) {
if (!user_access('bypass input data check') && !valid_input_data($data)) {
watchdog('error', t('Possible exploit abuse: invalid data.'));
watchdog('security', t('Possible exploit abuse: invalid data.'), WATCHDOG_WARNING);
drupal_set_message(t('File upload failed: invalid data.'), 'error');
return 0;
}

View File

@ -30,7 +30,7 @@ function _locale_add_language($code, $name, $onlylanguage = TRUE) {
}
drupal_set_message($message);
watchdog('special', t('%language language (%locale) added.', array('%language' => "<em>$name</em>", '%locale' => "<em>$code</em>")));
watchdog('locale', t('%language language (%locale) added.', array('%language' => "<em>$name</em>", '%locale' => "<em>$code</em>")));
}
/**
@ -257,7 +257,7 @@ function _locale_import_po($file, $lang, $mode) {
menu_rebuild();
drupal_set_message(t('Translation successfully imported. %number translated strings added to language, %update strings updated.', array('%number' => $additions, '%update' => $updates)));
watchdog('special', t('Imported %file into %locale: %number new strings added and %update updated.', array('%file' => "<em>$file->filename</em>", '%locale' => "<em>$lang</em>", '%number' => $additions, '%update' => $updates)));
watchdog('locale', t('Imported %file into %locale: %number new strings added and %update updated.', array('%file' => "<em>$file->filename</em>", '%locale' => "<em>$lang</em>", '%number' => $additions, '%update' => $updates)));
return TRUE;
}
@ -768,7 +768,7 @@ function _locale_export_po($language) {
$header .= "\"Plural-Forms: nplurals=". $meta->plurals ."; plural=". strtr($meta->formula, '$', '') .";\\n\"\n";
}
$header .= "\n";
watchdog('special', t('Exported %locale translation file: %filename.', array('%locale' => "<em>$meta->name</em>", '%filename' => "<em>$filename</em>")));
watchdog('locale', t('Exported %locale translation file: %filename.', array('%locale' => "<em>$meta->name</em>", '%filename' => "<em>$filename</em>")));
}
// Generating Portable Object Template
@ -789,7 +789,7 @@ function _locale_export_po($language) {
$header .= "\"Content-Transfer-Encoding: 8bit\\n\"\n";
$header .= "\"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n\"\n";
$header .= "\n";
watchdog('special', t('Exported translation file: %filename.', array('%filename' => "<em>$filename</em>")));
watchdog('locale', t('Exported translation file: %filename.', array('%filename' => "<em>$filename</em>")));
}
// Start download process

View File

@ -428,22 +428,16 @@ tr.watchdog-user {
tr.watchdog-user .active {
background: #eed;
}
tr.watchdog-special {
tr.watchdog-content {
background: #ddf;
}
tr.watchdog-special .active {
tr.watchdog-content .active {
background: #cce;
}
tr.watchdog-warning {
background: #fda;
}
tr.watchdog-warning .active {
background: #ec9;
}
tr.watchdog-httpd {
tr.watchdog-page-not-found, tr.watchdog-access-denied {
background: #dfd;
}
tr.watchdog-httpd .active {
tr.watchdog-pagenot-found .active, tr.watchdog-access-denied .active {
background: #cec;
}
tr.watchdog-error {

View File

@ -354,7 +354,7 @@ function aggregator_refresh($feed) {
break;
case 301:
$feed['url'] = $result->redirect_url;
watchdog('special', t('Aggregator: updated URL for feed %title to %url.', array('%title' => '<em>'. $feed['title'] .'</em>', '%url' => '<em>'. $feed['url'] .'</em>')));
watchdog('aggregator', t('Updated URL for feed %title to %url.', array('%title' => '<em>'. $feed['title'] .'</em>', '%url' => '<em>'. $feed['url'] .'</em>')));
break;
case 200:
@ -402,13 +402,15 @@ function aggregator_refresh($feed) {
cache_clear_all();
watchdog('status', t('Aggregator: syndicated content from %site.', array('%site' => '<em>'. $feed[title] .'</em>')));
drupal_set_message(t('Syndicated content from %site.', array('%site' => '<em>'. $feed['title'] .'</em>')));
$message = t('Syndicated content from %site.', array('%site' => '<em>'. $feed[title] .'</em>'));
watchdog('aggregator', $message);
drupal_set_message($message);
}
break;
default:
watchdog('error', t('Aggregator: failed to parse RSS feed %site: %error.', array('%site' => '<em>'. $feed['title'] .'</em>', '%error' => "<em>$result->code $result->error</em>")));
drupal_set_message(t('Failed to parse RSS feed %site: %error.', array('%site' => '<em>'. $feed['title'] .'</em>', '%error' => "<em>$result->code $result->error</em>")));
$message = t('Failed to parse RSS feed %site: %error.', array('%site' => '<em>'. $feed['title'] .'</em>', '%error' => "<em>$result->code $result->error</em>"));
watchdog('aggregator', $message, WATCHDOG_WARNING);
drupal_set_message($message);
}
}
@ -464,8 +466,9 @@ function aggregator_parse_feed(&$data, $feed) {
xml_set_character_data_handler($xml_parser, 'aggregator_element_data');
if (!xml_parse($xml_parser, $data, 1)) {
watchdog('error', t('Aggregator: failed to parse RSS feed %site: %error at line %line.', array('%site' => '<em>'. $feed['title'] .'</em>', '%error' => xml_error_string(xml_get_error_code($xml_parser)), '%line' => xml_get_current_line_number($xml_parser))));
drupal_set_message(t('Failed to parse RSS feed %site: %error at line %line.', array('%site' => '<em>'. $feed['title'] .'</em>', '%error' => xml_error_string(xml_get_error_code($xml_parser)), '%line' => xml_get_current_line_number($xml_parser))), 'error');
$message = t('Failed to parse RSS feed %site: %error at line %line.', array('%site' => '<em>'. $feed['title'] .'</em>', '%error' => xml_error_string(xml_get_error_code($xml_parser)), '%line' => xml_get_current_line_number($xml_parser)));
watchdog('aggregator', $message, WATCHDOG_WARNING);
drupal_set_message($message, 'error');
return 0;
}
xml_parser_free($xml_parser);

View File

@ -354,7 +354,7 @@ function aggregator_refresh($feed) {
break;
case 301:
$feed['url'] = $result->redirect_url;
watchdog('special', t('Aggregator: updated URL for feed %title to %url.', array('%title' => '<em>'. $feed['title'] .'</em>', '%url' => '<em>'. $feed['url'] .'</em>')));
watchdog('aggregator', t('Updated URL for feed %title to %url.', array('%title' => '<em>'. $feed['title'] .'</em>', '%url' => '<em>'. $feed['url'] .'</em>')));
break;
case 200:
@ -402,13 +402,15 @@ function aggregator_refresh($feed) {
cache_clear_all();
watchdog('status', t('Aggregator: syndicated content from %site.', array('%site' => '<em>'. $feed[title] .'</em>')));
drupal_set_message(t('Syndicated content from %site.', array('%site' => '<em>'. $feed['title'] .'</em>')));
$message = t('Syndicated content from %site.', array('%site' => '<em>'. $feed[title] .'</em>'));
watchdog('aggregator', $message);
drupal_set_message($message);
}
break;
default:
watchdog('error', t('Aggregator: failed to parse RSS feed %site: %error.', array('%site' => '<em>'. $feed['title'] .'</em>', '%error' => "<em>$result->code $result->error</em>")));
drupal_set_message(t('Failed to parse RSS feed %site: %error.', array('%site' => '<em>'. $feed['title'] .'</em>', '%error' => "<em>$result->code $result->error</em>")));
$message = t('Failed to parse RSS feed %site: %error.', array('%site' => '<em>'. $feed['title'] .'</em>', '%error' => "<em>$result->code $result->error</em>"));
watchdog('aggregator', $message, WATCHDOG_WARNING);
drupal_set_message($message);
}
}
@ -464,8 +466,9 @@ function aggregator_parse_feed(&$data, $feed) {
xml_set_character_data_handler($xml_parser, 'aggregator_element_data');
if (!xml_parse($xml_parser, $data, 1)) {
watchdog('error', t('Aggregator: failed to parse RSS feed %site: %error at line %line.', array('%site' => '<em>'. $feed['title'] .'</em>', '%error' => xml_error_string(xml_get_error_code($xml_parser)), '%line' => xml_get_current_line_number($xml_parser))));
drupal_set_message(t('Failed to parse RSS feed %site: %error at line %line.', array('%site' => '<em>'. $feed['title'] .'</em>', '%error' => xml_error_string(xml_get_error_code($xml_parser)), '%line' => xml_get_current_line_number($xml_parser))), 'error');
$message = t('Failed to parse RSS feed %site: %error at line %line.', array('%site' => '<em>'. $feed['title'] .'</em>', '%error' => xml_error_string(xml_get_error_code($xml_parser)), '%line' => xml_get_current_line_number($xml_parser)));
watchdog('aggregator', $message, WATCHDOG_WARNING);
drupal_set_message($message, 'error');
return 0;
}
xml_parser_free($xml_parser);

View File

@ -149,7 +149,7 @@ function blogapi_new_post($req_params) {
$nid = node_save($node);
if ($nid) {
watchdog('special', t('%type: added %title using blog API.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => "<em>$node->title</em>")), l(t('view'), "node/$nid"));
watchdog('content', t('%type: added %title using blog API.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => "<em>$node->title</em>")), l(t('view'), "node/$nid"));
return new xmlrpcresp(new xmlrpcval($nid, 'string'));
}
@ -209,7 +209,7 @@ function blogapi_edit_post($req_params) {
}
$nid = node_save($node);
if ($nid) {
watchdog('special', t('%type: updated %title using blog API.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => "<em>$node->title</em>")), l(t('view'), "node/$nid"));
watchdog('content', t('%type: updated %title using blog API.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => "<em>$node->title</em>")), l(t('view'), "node/$nid"));
return new xmlrpcresp(new xmlrpcval(true, 'boolean'));
}

View File

@ -149,7 +149,7 @@ function blogapi_new_post($req_params) {
$nid = node_save($node);
if ($nid) {
watchdog('special', t('%type: added %title using blog API.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => "<em>$node->title</em>")), l(t('view'), "node/$nid"));
watchdog('content', t('%type: added %title using blog API.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => "<em>$node->title</em>")), l(t('view'), "node/$nid"));
return new xmlrpcresp(new xmlrpcval($nid, 'string'));
}
@ -209,7 +209,7 @@ function blogapi_edit_post($req_params) {
}
$nid = node_save($node);
if ($nid) {
watchdog('special', t('%type: updated %title using blog API.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => "<em>$node->title</em>")), l(t('view'), "node/$nid"));
watchdog('content', t('%type: updated %title using blog API.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => "<em>$node->title</em>")), l(t('view'), "node/$nid"));
return new xmlrpcresp(new xmlrpcval(true, 'boolean'));
}

View File

@ -723,7 +723,7 @@ function book_admin_save($nid, $edit = array()) {
}
$message = t('Updated book %title.', array('%title' => "<em>$book->title</em>"));
watchdog('special', $message);
watchdog('content', $message);
return $message;
}

View File

@ -723,7 +723,7 @@ function book_admin_save($nid, $edit = array()) {
}
$message = t('Updated book %title.', array('%title' => "<em>$book->title</em>"));
watchdog('special', $message);
watchdog('content', $message);
return $message;
}

View File

@ -520,7 +520,7 @@ function comment_post($edit) {
// validated/filtered data to perform such check.
$duplicate = db_result(db_query("SELECT COUNT(cid) FROM {comments} WHERE pid = %d AND nid = %d AND subject = '%s' AND comment = '%s'", $edit['pid'], $edit['nid'], $edit['subject'], $edit['comment']), 0);
if ($duplicate != 0) {
watchdog('warning', t('Comment: duplicate %subject.', array('%subject' => '<em>'. $edit['subject'] .'</em>')));
watchdog('content', t('Comment: duplicate %subject.', array('%subject' => '<em>'. $edit['subject'] .'</em>')), WATCHDOG_WARNING);
}
if ($edit['cid']) {
@ -535,7 +535,7 @@ function comment_post($edit) {
module_invoke_all('comment', 'update', $edit);
// Add entry to the watchdog log.
watchdog('special', t('Comment: updated %subject.', array('%subject' => '<em>'. $edit['subject'] .'</em>')), l(t('view'), 'node/'. $edit['nid'], NULL, NULL, 'comment-'. $edit['cid']));
watchdog('content', t('Comment: updated %subject.', array('%subject' => '<em>'. $edit['subject'] .'</em>')), l(t('view'), 'node/'. $edit['nid'], NULL, NULL, 'comment-'. $edit['cid']));
}
else {
// Add the comment to database.
@ -638,7 +638,7 @@ function comment_post($edit) {
module_invoke_all('comment', 'insert', $edit);
// Add an entry to the watchdog log.
watchdog('special', t('Comment: added %subject.', array('%subject' => '<em>'. $edit['subject'] .'</em>')), l(t('view'), 'node/'. $edit['nid'], NULL, NULL, 'comment-'. $edit['cid']));
watchdog('content', t('Comment: added %subject.', array('%subject' => '<em>'. $edit['subject'] .'</em>')), l(t('view'), 'node/'. $edit['nid'], NULL, NULL, 'comment-'. $edit['cid']));
}
// Clear the cache so an anonymous user can see his comment being added.
@ -659,7 +659,7 @@ function comment_post($edit) {
}
}
else {
watchdog('error', t('Comment: unauthorized comment submitted or comment submitted to a closed node %subject.', array('%subject' => '<em>'. $edit['subject'] .'</em>')));
watchdog('content', t('Comment: unauthorized comment submitted or comment submitted to a closed node %subject.', array('%subject' => '<em>'. $edit['subject'] .'</em>')), WATCHDOG_WARNING);
}
}
@ -986,7 +986,7 @@ function comment_delete($cid) {
function comment_save($id, $edit) {
db_query("UPDATE {comments} SET subject = '%s', comment = '%s', status = %d, format = '%s', name = '%s', mail = '%s', homepage = '%s' WHERE cid = %d", $edit['subject'], $edit['comment'], $edit['status'], $edit['format'], $edit['name'], $edit['mail'], $edit['homepage'], $id);
watchdog('special', t('Comment: modified %subject.', array('%subject' => '<em>'. $edit['subject'] .'</em>')));
watchdog('content', t('Comment: modified %subject.', array('%subject' => '<em>'. $edit['subject'] .'</em>')));
drupal_set_message(t('The comment has been saved.'));
}
@ -1614,7 +1614,7 @@ function theme_comment_post_forbidden() {
function _comment_delete_thread($comment) {
// Delete the comment:
db_query('DELETE FROM {comments} WHERE cid = %d', $comment->cid);
watchdog('special', t('Comment: deleted %subject.', array('%subject' => "<em>$comment->subject</em>")));
watchdog('content', t('Comment: deleted %subject.', array('%subject' => "<em>$comment->subject</em>")));
module_invoke_all('comment', 'delete', $comment);

View File

@ -520,7 +520,7 @@ function comment_post($edit) {
// validated/filtered data to perform such check.
$duplicate = db_result(db_query("SELECT COUNT(cid) FROM {comments} WHERE pid = %d AND nid = %d AND subject = '%s' AND comment = '%s'", $edit['pid'], $edit['nid'], $edit['subject'], $edit['comment']), 0);
if ($duplicate != 0) {
watchdog('warning', t('Comment: duplicate %subject.', array('%subject' => '<em>'. $edit['subject'] .'</em>')));
watchdog('content', t('Comment: duplicate %subject.', array('%subject' => '<em>'. $edit['subject'] .'</em>')), WATCHDOG_WARNING);
}
if ($edit['cid']) {
@ -535,7 +535,7 @@ function comment_post($edit) {
module_invoke_all('comment', 'update', $edit);
// Add entry to the watchdog log.
watchdog('special', t('Comment: updated %subject.', array('%subject' => '<em>'. $edit['subject'] .'</em>')), l(t('view'), 'node/'. $edit['nid'], NULL, NULL, 'comment-'. $edit['cid']));
watchdog('content', t('Comment: updated %subject.', array('%subject' => '<em>'. $edit['subject'] .'</em>')), l(t('view'), 'node/'. $edit['nid'], NULL, NULL, 'comment-'. $edit['cid']));
}
else {
// Add the comment to database.
@ -638,7 +638,7 @@ function comment_post($edit) {
module_invoke_all('comment', 'insert', $edit);
// Add an entry to the watchdog log.
watchdog('special', t('Comment: added %subject.', array('%subject' => '<em>'. $edit['subject'] .'</em>')), l(t('view'), 'node/'. $edit['nid'], NULL, NULL, 'comment-'. $edit['cid']));
watchdog('content', t('Comment: added %subject.', array('%subject' => '<em>'. $edit['subject'] .'</em>')), l(t('view'), 'node/'. $edit['nid'], NULL, NULL, 'comment-'. $edit['cid']));
}
// Clear the cache so an anonymous user can see his comment being added.
@ -659,7 +659,7 @@ function comment_post($edit) {
}
}
else {
watchdog('error', t('Comment: unauthorized comment submitted or comment submitted to a closed node %subject.', array('%subject' => '<em>'. $edit['subject'] .'</em>')));
watchdog('content', t('Comment: unauthorized comment submitted or comment submitted to a closed node %subject.', array('%subject' => '<em>'. $edit['subject'] .'</em>')), WATCHDOG_WARNING);
}
}
@ -986,7 +986,7 @@ function comment_delete($cid) {
function comment_save($id, $edit) {
db_query("UPDATE {comments} SET subject = '%s', comment = '%s', status = %d, format = '%s', name = '%s', mail = '%s', homepage = '%s' WHERE cid = %d", $edit['subject'], $edit['comment'], $edit['status'], $edit['format'], $edit['name'], $edit['mail'], $edit['homepage'], $id);
watchdog('special', t('Comment: modified %subject.', array('%subject' => '<em>'. $edit['subject'] .'</em>')));
watchdog('content', t('Comment: modified %subject.', array('%subject' => '<em>'. $edit['subject'] .'</em>')));
drupal_set_message(t('The comment has been saved.'));
}
@ -1614,7 +1614,7 @@ function theme_comment_post_forbidden() {
function _comment_delete_thread($comment) {
// Delete the comment:
db_query('DELETE FROM {comments} WHERE cid = %d', $comment->cid);
watchdog('special', t('Comment: deleted %subject.', array('%subject' => "<em>$comment->subject</em>")));
watchdog('content', t('Comment: deleted %subject.', array('%subject' => "<em>$comment->subject</em>")));
module_invoke_all('comment', 'delete', $comment);

View File

@ -95,7 +95,7 @@ function drupal_directory_ping($arguments) {
db_query("DELETE FROM {directory} WHERE link = '%s' OR mail = '%s'", $link, $mail);
db_query("INSERT INTO {directory} (link, name, mail, slogan, mission, timestamp) VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $link, $name, $mail, $slogan, $mission, time());
watchdog('directory ping', t('ping from %name (%link).', array('%name' => "<em>$name</em>", '%link' => "<em>$link</em>")));
watchdog('directory ping', t('Ping from %name (%link).', array('%name' => "<em>$name</em>", '%link' => "<em>$link</em>")));
return new xmlrpcresp(new xmlrpcval(1, 'int'));
}
@ -143,7 +143,7 @@ function drupal_notify($server) {
$result = $client->send($message, 5);
if (!$result || $result->faultCode()) {
watchdog('error', t('Failed to notify %url at %path: %error.', array('%url' => '<em>'. $url["host"] .'</em>', '%path' => '<em>'. $url["path"] .'</em>', '%error' => '<em>'. $result->faultString() .'</em>')));
watchdog('directory ping', t('Failed to notify %url at %path: %error.', array('%url' => '<em>'. $url["host"] .'</em>', '%path' => '<em>'. $url["path"] .'</em>', '%error' => '<em>'. $result->faultString() .'</em>')), WATCHDOG_WARNING);
}
}

View File

@ -95,7 +95,7 @@ function drupal_directory_ping($arguments) {
db_query("DELETE FROM {directory} WHERE link = '%s' OR mail = '%s'", $link, $mail);
db_query("INSERT INTO {directory} (link, name, mail, slogan, mission, timestamp) VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $link, $name, $mail, $slogan, $mission, time());
watchdog('directory ping', t('ping from %name (%link).', array('%name' => "<em>$name</em>", '%link' => "<em>$link</em>")));
watchdog('directory ping', t('Ping from %name (%link).', array('%name' => "<em>$name</em>", '%link' => "<em>$link</em>")));
return new xmlrpcresp(new xmlrpcval(1, 'int'));
}
@ -143,7 +143,7 @@ function drupal_notify($server) {
$result = $client->send($message, 5);
if (!$result || $result->faultCode()) {
watchdog('error', t('Failed to notify %url at %path: %error.', array('%url' => '<em>'. $url["host"] .'</em>', '%path' => '<em>'. $url["path"] .'</em>', '%error' => '<em>'. $result->faultString() .'</em>')));
watchdog('directory ping', t('Failed to notify %url at %path: %error.', array('%url' => '<em>'. $url["host"] .'</em>', '%path' => '<em>'. $url["path"] .'</em>', '%error' => '<em>'. $result->faultString() .'</em>')), WATCHDOG_WARNING);
}
}

View File

@ -288,8 +288,9 @@ function locale_admin_manage() {
if (isset($languages['name'][$edit['langcode']])) {
db_query("DELETE FROM {locales_meta} WHERE locale = '%s'", $edit['langcode']);
db_query("DELETE FROM {locales_target} WHERE locale = '%s'", $edit['langcode']);
drupal_set_message(t('%locale language removed.', array('%locale' => '<em>'. t($languages['name'][$edit['langcode']]) .'</em>')));
watchdog('special', t('%locale language removed.', array('%locale' => '<em>'. $edit['langcode'] .'</em>')));
$message = t('%locale language removed.', array('%locale' => '<em>'. t($languages['name'][$edit['langcode']]) .'</em>'));
drupal_set_message($message);
watchdog('locale', $message);
}
// Changing the locale settings impacts the interface:
@ -379,7 +380,9 @@ function locale_admin_import() {
// Now import strings into the language
$file = file_check_upload('file');
if ($ret = _locale_import_po($file, $edit['langcode'], $edit['mode']) == FALSE) {
watchdog('error', t('Translation import of %filename failed.', array('%filename' => "<em>$file->filename</em>")));
$message = t('Translation import of %filename failed.', array('%filename' => "<em>$file->filename</em>"));
drupal_set_message($message, 'error');
watchdog('locale', $message, WATCHDOG_ERROR);
}
drupal_goto('admin/locale');

View File

@ -288,8 +288,9 @@ function locale_admin_manage() {
if (isset($languages['name'][$edit['langcode']])) {
db_query("DELETE FROM {locales_meta} WHERE locale = '%s'", $edit['langcode']);
db_query("DELETE FROM {locales_target} WHERE locale = '%s'", $edit['langcode']);
drupal_set_message(t('%locale language removed.', array('%locale' => '<em>'. t($languages['name'][$edit['langcode']]) .'</em>')));
watchdog('special', t('%locale language removed.', array('%locale' => '<em>'. $edit['langcode'] .'</em>')));
$message = t('%locale language removed.', array('%locale' => '<em>'. t($languages['name'][$edit['langcode']]) .'</em>'));
drupal_set_message($message);
watchdog('locale', $message);
}
// Changing the locale settings impacts the interface:
@ -379,7 +380,9 @@ function locale_admin_import() {
// Now import strings into the language
$file = file_check_upload('file');
if ($ret = _locale_import_po($file, $edit['langcode'], $edit['mode']) == FALSE) {
watchdog('error', t('Translation import of %filename failed.', array('%filename' => "<em>$file->filename</em>")));
$message = t('Translation import of %filename failed.', array('%filename' => "<em>$file->filename</em>"));
drupal_set_message($message, 'error');
watchdog('locale', $message, WATCHDOG_ERROR);
}
drupal_goto('admin/locale');

View File

@ -1400,7 +1400,7 @@ function node_submit(&$node) {
// perform this operation:
if (node_access('update', $node)) {
$node->nid = node_save($node);
watchdog('special', t('%type: updated %title.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => "<em>$node->title</em>")), l(t('view'), 'node/'. $node->nid));
watchdog('content', t('%type: updated %title.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => "<em>$node->title</em>")), l(t('view'), 'node/'. $node->nid));
$msg = t('The %post was updated.', array ('%post' => node_invoke($node, 'node_name')));
}
}
@ -1409,7 +1409,7 @@ function node_submit(&$node) {
// perform this operation:
if (node_access('create', $node)) {
$node->nid = node_save($node);
watchdog('special', t('%type: added %title.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => "<em>$node->title</em>")), l(t('view'), "node/$node->nid"));
watchdog('content', t('%type: added %title.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => "<em>$node->title</em>")), l(t('view'), "node/$node->nid"));
$msg = t('Your %post was created.', array ('%post' => node_invoke($node, 'node_name')));
}
}
@ -1444,7 +1444,7 @@ function node_delete($edit) {
search_wipe($node->nid, 'node');
}
watchdog('special', t('%type: deleted %title.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => "<em>$node->title</em>")));
watchdog('content', t('%type: deleted %title.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => "<em>$node->title</em>")));
$output = t('The node has been deleted.');
}
else {

View File

@ -1400,7 +1400,7 @@ function node_submit(&$node) {
// perform this operation:
if (node_access('update', $node)) {
$node->nid = node_save($node);
watchdog('special', t('%type: updated %title.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => "<em>$node->title</em>")), l(t('view'), 'node/'. $node->nid));
watchdog('content', t('%type: updated %title.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => "<em>$node->title</em>")), l(t('view'), 'node/'. $node->nid));
$msg = t('The %post was updated.', array ('%post' => node_invoke($node, 'node_name')));
}
}
@ -1409,7 +1409,7 @@ function node_submit(&$node) {
// perform this operation:
if (node_access('create', $node)) {
$node->nid = node_save($node);
watchdog('special', t('%type: added %title.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => "<em>$node->title</em>")), l(t('view'), "node/$node->nid"));
watchdog('content', t('%type: added %title.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => "<em>$node->title</em>")), l(t('view'), "node/$node->nid"));
$msg = t('Your %post was created.', array ('%post' => node_invoke($node, 'node_name')));
}
}
@ -1444,7 +1444,7 @@ function node_delete($edit) {
search_wipe($node->nid, 'node');
}
watchdog('special', t('%type: deleted %title.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => "<em>$node->title</em>")));
watchdog('content', t('%type: deleted %title.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => "<em>$node->title</em>")));
$output = t('The node has been deleted.');
}
else {

View File

@ -63,7 +63,7 @@ function ping_ping($name = '', $url = '') {
$result = $client->send($message);
if (!$result || $result->faultCode()) {
watchdog('error', t('Failed to notify pingomatic.com (site).'));
watchdog('directory ping', t('Failed to notify pingomatic.com (site).'), WATCHDOG_WARNING);
}
}

View File

@ -63,7 +63,7 @@ function ping_ping($name = '', $url = '') {
$result = $client->send($message);
if (!$result || $result->faultCode()) {
watchdog('error', t('Failed to notify pingomatic.com (site).'));
watchdog('directory ping', t('Failed to notify pingomatic.com (site).'), WATCHDOG_WARNING);
}
}

View File

@ -78,34 +78,34 @@ function queue_vote($node, $vote) {
$node->moderate = 0;
$node->promote = 1;
node_save($node);
watchdog('special', t('Moderation: approved %title.', array('%title' => "<em>$node->title</em>")));
watchdog('content', t('Moderation: approved %title.', array('%title' => "<em>$node->title</em>")));
drupal_set_message(t('The post is promoted.'));
}
else if (variable_get('queue_threshold_dump', -2) >= $node->score) {
if ($node->revisions) {
node_revision_rollback($node, end(node_revision_list($node)));
watchdog('special', t('Moderation: declined %title (rollback).', array('%title' => "<em>$node->title</em>")));
watchdog('content', t('Moderation: declined %title (rollback).', array('%title' => "<em>$node->title</em>")));
drupal_set_message(t('The post has been declined and the previous version has been restored.'));
}
else {
$node->moderate = 0;
$node->status = 0;
node_save($node);
watchdog('special', t('Moderation: declined %title.', array('%title' => "<em>$node->title</em>")));
watchdog('content', t('Moderation: declined %title.', array('%title' => "<em>$node->title</em>")));
drupal_set_message(t('The post has been declined.'));
}
}
else if (variable_get('queue_threshold_expire', 8) <= $node->votes) {
if ($node->revisions) {
node_revision_rollback($node, end(node_revision_list($node)));
watchdog('special', t('Moderation: expired %title (rollback).', array('%title' => "<em>$node->title</em>")));
watchdog('content', t('Moderation: expired %title (rollback).', array('%title' => "<em>$node->title</em>")));
drupal_set_message(t('The post has expired and the previous version has been restored.'));
}
else {
$node->moderate = 0;
$node->status = 0;
node_save($node);
watchdog('special', t('Moderation: expired %title.', array('%title' => "<em>$node->title</em>")));
watchdog('content', t('Moderation: expired %title.', array('%title' => "<em>$node->title</em>")));
drupal_set_message(t('The post has expired.'));
}
}

View File

@ -936,7 +936,7 @@ function user_pass() {
drupal_set_message(t('Your password and further instructions have been sent to your e-mail address.'));
}
else {
watchdog('error', t('Error mailing password to %name at %email.', array('%name' => '<em>'. $account->name .'</em>', '%email' => '<em>'. $account->mail .'</em>')));
watchdog('user', t('Error mailing password to %name at %email.', array('%name' => '<em>'. $account->name .'</em>', '%email' => '<em>'. $account->mail .'</em>')), WATCHDOG_ERROR);
drupal_set_message(t('Unable to send mail. Please contact the site admin.'));
}
drupal_goto('user');
@ -1133,7 +1133,7 @@ function user_edit($category = 'account') {
if (!form_get_errors()) {
// Validate input to ensure that non-privileged users can't alter protected data.
if (!user_access('administer users') && array_intersect(array_keys($edit), array('uid', 'roles', 'init', 'session'))) {
watchdog('warning', t('Detected malicious attempt to alter protected user fields.'));
watchdog('security', t('Detected malicious attempt to alter protected user fields.'), WATCHDOG_WARNING);
}
else {
user_save($account, $edit, $category);

View File

@ -936,7 +936,7 @@ function user_pass() {
drupal_set_message(t('Your password and further instructions have been sent to your e-mail address.'));
}
else {
watchdog('error', t('Error mailing password to %name at %email.', array('%name' => '<em>'. $account->name .'</em>', '%email' => '<em>'. $account->mail .'</em>')));
watchdog('user', t('Error mailing password to %name at %email.', array('%name' => '<em>'. $account->name .'</em>', '%email' => '<em>'. $account->mail .'</em>')), WATCHDOG_ERROR);
drupal_set_message(t('Unable to send mail. Please contact the site admin.'));
}
drupal_goto('user');
@ -1133,7 +1133,7 @@ function user_edit($category = 'account') {
if (!form_get_errors()) {
// Validate input to ensure that non-privileged users can't alter protected data.
if (!user_access('administer users') && array_intersect(array_keys($edit), array('uid', 'roles', 'init', 'session'))) {
watchdog('warning', t('Detected malicious attempt to alter protected user fields.'));
watchdog('security', t('Detected malicious attempt to alter protected user fields.'), WATCHDOG_WARNING);
}
else {
user_save($account, $edit, $category);

View File

@ -63,6 +63,11 @@ function watchdog_cron() {
* Menu callback; displays a listing of log messages.
*/
function watchdog_overview() {
$icons = array(WATCHDOG_NOTICE => '',
WATCHDOG_WARNING => theme('image', 'misc/watchdog-warning.png', t('warning'), t('warning')),
WATCHDOG_ERROR => theme('image', 'misc/watchdog-error.png', t('error'), t('error')));
$classes = array(WATCHDOG_NOTICE => 'watchdog-notice', WATCHDOG_WARNING => 'watchdog-warning', WATCHDOG_ERROR => 'watchdog-error');
$names['all'] = t('all messages');
$queries['all'] = '';
foreach (_watchdog_get_message_types() as $type) {
@ -83,6 +88,7 @@ function watchdog_overview() {
$form .= form_submit(t('Filter'));
$header = array(
' ',
array('data' => t('Type'), 'field' => 'w.type'),
array('data' => t('Date'), 'field' => 'w.timestamp', 'sort' => 'desc'),
array('data' => t('Message'), 'field' => 'w.message'),
@ -96,25 +102,26 @@ function watchdog_overview() {
$rows[] = array('data' =>
array(
// Cells
$icons[$watchdog->severity],
$watchdog->type,
format_date($watchdog->timestamp, 'small'),
truncate_utf8(strip_tags($watchdog->message), 64),
truncate_utf8($watchdog->message, 64),
format_name($watchdog),
$watchdog->link,
l(t('details'), "admin/logs/event/$watchdog->wid")
),
// Attributes for tr
'class' => "watchdog-$watchdog->type"
'class' => "watchdog-". preg_replace('/[^a-z]/i', '-', $watchdog->type) .' '. $classes[$watchdog->severity]
);
}
if (!$rows) {
$rows[] = array(array('data' => t('No log messages available.'), 'colspan' => '6'));
$rows[] = array(array('data' => t('No log messages available.'), 'colspan' => '7'));
}
$pager = theme('pager', NULL, 50, 0, tablesort_pager());
if (!empty($pager)) {
$rows[] = array(array('data' => $pager, 'colspan' => '6'));
$rows[] = array(array('data' => $pager, 'colspan' => '7'));
}
$output = '<div class="container-inline">'. form($form) .'</div>';
@ -127,6 +134,7 @@ function watchdog_overview() {
* Menu callback; displays details about a log message.
*/
function watchdog_event($id) {
$severity = array(WATCHDOG_NOTICE => t('notice'), WATCHDOG_WARNING => t('warning'), WATCHDOG_ERROR => t('error'));
$output = '';
$result = db_query('SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid WHERE w.wid = %d', $id);
if ($watchdog = db_fetch_object($result)) {
@ -136,6 +144,7 @@ function watchdog_event($id) {
$output .= ' <tr><th>'. t('User') .'</th><td>'. format_name($watchdog) .'</td></tr>';
$output .= ' <tr><th>'. t('Location') ."</th><td>". l($watchdog->location, $watchdog->location) ."</td></tr>";
$output .= ' <tr><th>'. t('Message') ."</th><td>$watchdog->message</td></tr>";
$output .= ' <tr><th>'. t('Severity') .'</th><td>'. $severity[$watchdog->severity] .'</td></tr>';
$output .= ' <tr><th>'. t('Hostname') ."</th><td>$watchdog->hostname</td></tr>";
$output .= '</table>';
}
@ -145,7 +154,7 @@ function watchdog_event($id) {
function _watchdog_get_message_types() {
$types = array();
$result = db_query('SELECT DISTINCT(type) FROM {watchdog}');
$result = db_query('SELECT DISTINCT(type) FROM {watchdog} ORDER BY type');
while ($object = db_fetch_object($result)) {
$types[] = $object->type;
}

View File

@ -63,6 +63,11 @@ function watchdog_cron() {
* Menu callback; displays a listing of log messages.
*/
function watchdog_overview() {
$icons = array(WATCHDOG_NOTICE => '',
WATCHDOG_WARNING => theme('image', 'misc/watchdog-warning.png', t('warning'), t('warning')),
WATCHDOG_ERROR => theme('image', 'misc/watchdog-error.png', t('error'), t('error')));
$classes = array(WATCHDOG_NOTICE => 'watchdog-notice', WATCHDOG_WARNING => 'watchdog-warning', WATCHDOG_ERROR => 'watchdog-error');
$names['all'] = t('all messages');
$queries['all'] = '';
foreach (_watchdog_get_message_types() as $type) {
@ -83,6 +88,7 @@ function watchdog_overview() {
$form .= form_submit(t('Filter'));
$header = array(
' ',
array('data' => t('Type'), 'field' => 'w.type'),
array('data' => t('Date'), 'field' => 'w.timestamp', 'sort' => 'desc'),
array('data' => t('Message'), 'field' => 'w.message'),
@ -96,25 +102,26 @@ function watchdog_overview() {
$rows[] = array('data' =>
array(
// Cells
$icons[$watchdog->severity],
$watchdog->type,
format_date($watchdog->timestamp, 'small'),
truncate_utf8(strip_tags($watchdog->message), 64),
truncate_utf8($watchdog->message, 64),
format_name($watchdog),
$watchdog->link,
l(t('details'), "admin/logs/event/$watchdog->wid")
),
// Attributes for tr
'class' => "watchdog-$watchdog->type"
'class' => "watchdog-". preg_replace('/[^a-z]/i', '-', $watchdog->type) .' '. $classes[$watchdog->severity]
);
}
if (!$rows) {
$rows[] = array(array('data' => t('No log messages available.'), 'colspan' => '6'));
$rows[] = array(array('data' => t('No log messages available.'), 'colspan' => '7'));
}
$pager = theme('pager', NULL, 50, 0, tablesort_pager());
if (!empty($pager)) {
$rows[] = array(array('data' => $pager, 'colspan' => '6'));
$rows[] = array(array('data' => $pager, 'colspan' => '7'));
}
$output = '<div class="container-inline">'. form($form) .'</div>';
@ -127,6 +134,7 @@ function watchdog_overview() {
* Menu callback; displays details about a log message.
*/
function watchdog_event($id) {
$severity = array(WATCHDOG_NOTICE => t('notice'), WATCHDOG_WARNING => t('warning'), WATCHDOG_ERROR => t('error'));
$output = '';
$result = db_query('SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid WHERE w.wid = %d', $id);
if ($watchdog = db_fetch_object($result)) {
@ -136,6 +144,7 @@ function watchdog_event($id) {
$output .= ' <tr><th>'. t('User') .'</th><td>'. format_name($watchdog) .'</td></tr>';
$output .= ' <tr><th>'. t('Location') ."</th><td>". l($watchdog->location, $watchdog->location) ."</td></tr>";
$output .= ' <tr><th>'. t('Message') ."</th><td>$watchdog->message</td></tr>";
$output .= ' <tr><th>'. t('Severity') .'</th><td>'. $severity[$watchdog->severity] .'</td></tr>';
$output .= ' <tr><th>'. t('Hostname') ."</th><td>$watchdog->hostname</td></tr>";
$output .= '</table>';
}
@ -145,7 +154,7 @@ function watchdog_event($id) {
function _watchdog_get_message_types() {
$types = array();
$result = db_query('SELECT DISTINCT(type) FROM {watchdog}');
$result = db_query('SELECT DISTINCT(type) FROM {watchdog} ORDER BY type');
while ($object = db_fetch_object($result)) {
$types[] = $object->type;
}