Log an event message.
This hook allows modules to route log events to custom destinations, such as SMS, Email, pager, syslog, ...etc.
array $log_entry: An associative array containing the following keys:
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
function hook_watchdog(array $log_entry) {
global $base_url;
$language_interface = language(\Drupal\Core\Language\Language::TYPE_INTERFACE);
$severity_list = 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'),
);
$to = 'someone@example.com';
$params = array();
$params['subject'] = t('[@site_name] @severity_desc: Alert from your web site', array(
'@site_name' => config('system.site')
->get('name'),
'@severity_desc' => $severity_list[$log_entry['severity']],
));
$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['uid'],
'@name' => $log_entry['user']->name,
'@link' => strip_tags($log_entry['link']),
'@message' => strip_tags($log_entry['message']),
));
drupal_mail('emaillog', 'entry', $to, $language_interface->langcode, $params);
}