function elasticsearch_watchdog_watchdog in Elasticsearch Connector 7.2
Same name and namespace in other branches
- 7.5 modules/elasticsearch_watchdog/elasticsearch_watchdog.module \elasticsearch_watchdog_watchdog()
- 7 modules/elasticsearch_watchdog/elasticsearch_watchdog.module \elasticsearch_watchdog_watchdog()
Implements hook_watchdog().
File
- modules/
elasticsearch_watchdog/ elasticsearch_watchdog.module, line 105 - Created on Jan 06, 2014
Code
function elasticsearch_watchdog_watchdog(array $log_entry) {
global $base_url;
$user = $GLOBALS['user'];
$client_id = elasticsearch_watchdog_get_cluster_id();
if (!empty($client_id)) {
$client = elasticsearch_connector_get_client_by_id($client_id);
if ($client) {
$doc = array();
$doc['index'] = elasticsearch_watchdog_get_index_name();
$doc['type'] = elasticsearch_watchdog_get_type_name();
// Workaround to order the logs if the same timestamp based on microtime.
$microtime_float = explode('.', microtime(TRUE));
if (empty($microtime_float[1])) {
$microtime = '0.0';
}
else {
$microtime = '0.' . $microtime_float[1];
}
$doc['body'] = array(
'uid' => $log_entry['uid'],
'username' => user_is_logged_in() ? $user->name : 'Anonymous',
'type' => substr($log_entry['type'], 0, 64),
'message' => $log_entry['message'],
'full_massage' => format_string($log_entry['message'], (array) $log_entry['variables']),
'variables' => serialize($log_entry['variables']),
'severity' => $log_entry['severity'],
'link' => substr($log_entry['link'], 0, 255),
'location' => $log_entry['request_uri'],
'referer' => $log_entry['referer'],
'hostname' => substr($log_entry['ip'], 0, 128),
'timestamp' => $log_entry['timestamp'],
'microtime' => (double) $microtime,
'domain' => $base_url,
'date' => date('c', $log_entry['timestamp']),
);
$doc['ttl'] = variable_get('elasticsearch_watchdog_ttl', ELASTICSEARCH_WATCHDOG_DEFAULT_INTERVAL);
// Indexing document.
try {
$ret = $client
->index($doc);
} catch (Exception $e) {
error_log($e
->getMessage());
}
}
}
}