hook_watchdog
Definition
hook_watchdog($log_msg)
developer/hooks/core.php, line 1834
Description
Log an event message
This hook allows modules to route log events to custom destinations, such as SMS, Email, pager, syslog, ...etc.
Parameters
$log_entry The log_entry is 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.
- request_uri: The Request URI for the page the event happened in.
- referer: The page that referred the use to the page where the event occurred.
- ip: The IP address where the request for the page came from.
- timestamp: The UNIX timetamp of the date/time the event occurred
- severity: One of the following values as defined in RFC 3164
- link: an optional link provided by the module that called the watchdog() function.
- message: The text of the message to be logged.
Return value
None.
Related topics
| Name | Description |
|---|---|
| Hooks | Allow modules to interact with the Drupal core. |
Code
<?php
function hook_watchdog($log_msg) {
global $base_url;
$severity_list = array(
WATCHDOG_EMERG => 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'),
);
$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']),
));
drupal_mail('emaillog', $to, $subject, $body, $from = NULL, $headers = array());
}
}
?> 