| 5 bootstrap.inc | watchdog($type, $message, $severity = WATCHDOG_NOTICE, $link = NULL) |
| 6 bootstrap.inc | watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) |
| 7 bootstrap.inc | watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) |
| 8 bootstrap.inc | watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) |
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.
See also
119 calls to watchdog()
15 string references to 'watchdog'
File
- includes/
bootstrap.inc, line 1710 - 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_implements')) {
$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(),
'timestamp' => REQUEST_TIME,
);
// Call the logging hooks to log/process the message
foreach (module_implements('watchdog') as $module) {
module_invoke($module, '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;
}
}
Login or register to post comments
Comments
Watchdog Severity Levels
http://api.drupal.org/api/drupal/includes--common.inc/function/watchdog_...
<?phpfunction watchdog_severity_levels() {
return array(
WATCHDOG_EMERGENCY => t('emergency'),
WATCHDOG_ALERT => t('alert'),
WATCHDOG_CRITICAL => t('critical'),
WATCHDOG_ERROR => t('error'),
WATCHDOG_WARNING => t('warning'),
WATCHDOG_NOTICE => t('notice'),
WATCHDOG_INFO => t('info'),
WATCHDOG_DEBUG => t('debug'),
);
}
?>
Outputing Form ID
To output form id, insert the following into hooks_form_alter function:
watchdog('cg_volunteer', 'cg in form_alter %formly', array('%formly' => $form['#id']), WATCHDOG_NOTICE, $link = NULL);check /admin/reports/dblog for the output
The comment about t() is
The comment about t() is confusing because it does not say where the translation should occur. watchdog() invokes dblog_watchdog() in modules/dblog/dblog.module and dblog_watchdog() does not translate anything. The translation has to occur before watchdog() processes the data; You could, in theory, have the following complex code when the message is logged on behalf of another module.
watchdog(t('Name @x', array('@x' => 'A')), t('Message @y @z', array('@y' => 'BBBB')), array('@z' => 'CCCCCCCCCC'));