Skip to content

Instantly share code, notes, and snippets.

@andeersg
Created March 14, 2016 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andeersg/fe672c14bf85a6746599 to your computer and use it in GitHub Desktop.
Save andeersg/fe672c14bf85a6746599 to your computer and use it in GitHub Desktop.
Simple implementation of `hook_watchdog` to send messages to external service.
function hook_watchdog(array $log_entry) {
$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'),
);
if (strpos($log_entry['type'], 'debug') !== FALSE) {
$output = array(
'site' => $log_entry['type'],
'message' => t($log_entry['message'], $log_entry['variables']),
'status' => $severity_list[$log_entry['severity']],
);
drupal_http_request('', array(
'headers' => array(
'Content-Type' => 'application/json',
'Accept' => 'application/json'
),
'method' => 'POST',
'data' => json_encode($output),
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment