Same name and namespace in other branches
- 4.6.x includes/bootstrap.inc \watchdog()
- 4.7.x includes/bootstrap.inc \watchdog()
- 5.x includes/bootstrap.inc \watchdog()
- 6.x includes/bootstrap.inc \watchdog()
Logs a system message.
Parameters
$type: The category to which this message belongs. Can be any string, but the general practice is to use the name of the module calling watchdog().
$message: The message to store in the log. Keep $message translatable by not concatenating dynamic values into it! Variables in the message should be added by using placeholder strings alongside the variables argument to declare the value of the placeholders. See t() for documentation on how $message and $variables interact.
$variables: Array of variables to replace in the message on display or NULL if message is already translated or not possible to translate.
$severity: The severity of the message; one of the following values as defined in RFC 3164:
- WATCHDOG_EMERGENCY: Emergency, system is unusable.
- WATCHDOG_ALERT: Alert, action must be taken immediately.
- WATCHDOG_CRITICAL: Critical conditions.
- WATCHDOG_ERROR: Error conditions.
- WATCHDOG_WARNING: Warning conditions.
- WATCHDOG_NOTICE: (default) Normal but significant conditions.
- WATCHDOG_INFO: Informational messages.
- WATCHDOG_DEBUG: Debug-level messages.
$link: A link to associate with the message. SECURITY NOTE: Make sure your link is properly sanitized. Use the l() function to generate secure links.
See also
130 calls to watchdog()
- actions_do in includes/
actions.inc - Performs a given list of actions by executing their callback functions.
- actions_save in includes/
actions.inc - Saves an action and its user-supplied parameter values to the database.
- actions_synchronize in includes/
actions.inc - Synchronizes actions that are provided by modules in hook_action_info().
- aggregator_parse_feed in modules/
aggregator/ aggregator.parser.inc - Parses a feed and stores its items.
- aggregator_refresh in modules/
aggregator/ aggregator.module - Checks a news feed for new items.
16 string references to 'watchdog'
- actions_loop_test_watchdog in modules/
simpletest/ tests/ actions_loop_test.module - Implements hook_watchdog().
- bootstrap_hooks in includes/
bootstrap.inc - Defines the critical hooks that force modules to always be loaded.
- CommentActionsTestCase::clearWatchdog in modules/
comment/ comment.test - Helper function: clear the watchdog.
- DBLogTestCase::testFilter in modules/
dblog/ dblog.test - Tests the database log filter functionality at admin/reports/dblog.
- dblog_clear_log_submit in modules/
dblog/ dblog.admin.inc - Form submission handler for dblog_clear_log_form().
File
- includes/
bootstrap.inc, line 2051 - Functions that need to be loaded on every Drupal request.
Code
function watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) {
global $user, $base_root;
static $in_error_state = FALSE;
// It is possible that the error handling will itself trigger an error. In that case, we could
// end up in an infinite loop. To avoid that, we implement a simple static semaphore.
if (!$in_error_state && function_exists('module_invoke_all')) {
$in_error_state = TRUE;
// The user object may not exist in all conditions, so 0 is substituted if needed.
$user_uid = isset($user->uid) ? $user->uid : 0;
// Prepare the fields to be logged
$log_entry = array(
'type' => $type,
'message' => $message,
'variables' => $variables,
'severity' => $severity,
'link' => $link,
'user' => $user,
'uid' => $user_uid,
'request_uri' => $base_root . request_uri(),
'referer' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '',
'ip' => ip_address(),
// Request time isn't accurate for long processes, use time() instead.
'timestamp' => time(),
);
// Call the logging hooks to log/process the message
module_invoke_all('watchdog', $log_entry);
// It is critical that the semaphore is only cleared here, in the parent
// watchdog() call (not outside the loop), to prevent recursive execution.
$in_error_state = FALSE;
}
}