From 045c8016b370029c3b7b528ebfdf6e0bd55a2fcf Mon Sep 17 00:00:00 2001 From: jurgenhaas Date: Sun, 15 Feb 2015 17:10:42 +0100 Subject: [PATCH 1/2] Optionally submit some debugging details once for each request --- logs_http.admin.inc | 7 +++++++ logs_http.module | 27 +++++++++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/logs_http.admin.inc b/logs_http.admin.inc index 1f020c2..fe32565 100644 --- a/logs_http.admin.inc +++ b/logs_http.admin.inc @@ -16,6 +16,13 @@ function logs_http_admin_settings($form, &$form_state) { '#default_value' => variable_get('logs_http_enabled', TRUE), ); + $form['logs_http_debugging_mode'] = array( + '#type' => 'checkbox', + '#title' => t('Debugging mode'), + '#description' => t('If selected, each log entry will contain a lot more details about the current http request.'), + '#default_value' => variable_get('logs_http_debugging_mode', FALSE), + ); + $form['logs_http_url'] = array( '#type' => 'textfield', '#title' => t('Endpoint'), diff --git a/logs_http.module b/logs_http.module index 1f0cf79..8c40e48 100644 --- a/logs_http.module +++ b/logs_http.module @@ -139,12 +139,6 @@ function logs_http_register_event(array $log_entry) { 'severity' => $log_entry['severity'], ); - if (!empty($log_entry['variables']['exception_trace'])) { - // @todo: We avoid unserializing as it seems to causes Logs to fail - // to index event as JSON. - $event['exception_trace'] = base64_decode($log_entry['variables']['exception_trace']); - } - if ($uuid = variable_get('logs_http_uuid')) { $event['uuid'] = $uuid; } @@ -152,6 +146,27 @@ function logs_http_register_event(array $log_entry) { // Remove empty values, to prevent errors in the indexing of the JSON. $event = logs_http_array_remove_empty($event); + if (variable_get('logs_http_debugging_mode', FALSE)) { + if (!isset($events['debugging'])) { + $debugging_event = $event; + unset($debugging_event['type']); + unset($debugging_event['message']); + unset($debugging_event['severity']); + $debugging_event['debug_details'] = array( + 'GET' => $_GET, + 'POST' => $_POST, + 'COOKIE' => $_COOKIE, + ); + $events['debugging'] = $debugging_event; + } + } + + if (!empty($log_entry['variables']['exception_trace'])) { + // @todo: We avoid unserializing as it seems to causes Logs to fail + // to index event as JSON. + $event['exception_trace'] = base64_decode($log_entry['variables']['exception_trace']); + } + // Prevent identical events. $event_clone = $event; unset($event_clone['timestamp']); From 9349890446a5a3c45411e247b6bc36bcd9e362de Mon Sep 17 00:00:00 2001 From: jurgenhaas Date: Sat, 4 Apr 2015 13:48:59 +0200 Subject: [PATCH 2/2] Move extra debugging details to an alter hook --- logs_http.module | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/logs_http.module b/logs_http.module index 8c40e48..2845db5 100644 --- a/logs_http.module +++ b/logs_http.module @@ -139,6 +139,12 @@ function logs_http_register_event(array $log_entry) { 'severity' => $log_entry['severity'], ); + if (!empty($log_entry['variables']['exception_trace'])) { + // @todo: We avoid unserializing as it seems to causes Logs to fail + // to index event as JSON. + $event['exception_trace'] = base64_decode($log_entry['variables']['exception_trace']); + } + if ($uuid = variable_get('logs_http_uuid')) { $event['uuid'] = $uuid; } @@ -146,12 +152,35 @@ function logs_http_register_event(array $log_entry) { // Remove empty values, to prevent errors in the indexing of the JSON. $event = logs_http_array_remove_empty($event); + // Avoid infinite loops when drupal_alter should ever issue new events. + static $alter_active; + if (empty($alter_active)) { + $alter_active = TRUE; + // Allow other modules to alter the event before being registered. + drupal_alter('logs_http_event', $event); + $alter_active = FALSE; + } + + // Prevent identical events. + $event_clone = $event; + unset($event_clone['timestamp']); + $key = md5(serialize($event_clone)); + $events[$key] = $event; +} + +/** + * Implements hook_logs_http_event_alter(). + */ +function logs_http_logs_http_event_alter(&$event) { if (variable_get('logs_http_debugging_mode', FALSE)) { + $events = &drupal_static('logs_http_events', array()); if (!isset($events['debugging'])) { $debugging_event = $event; - unset($debugging_event['type']); - unset($debugging_event['message']); - unset($debugging_event['severity']); + foreach (array('type', 'message', 'severity', 'exception_trace') as $key) { + if (isset($debugging_event[$key])) { + unset($debugging_event[$key]); + } + } $debugging_event['debug_details'] = array( 'GET' => $_GET, 'POST' => $_POST, @@ -160,18 +189,6 @@ function logs_http_register_event(array $log_entry) { $events['debugging'] = $debugging_event; } } - - if (!empty($log_entry['variables']['exception_trace'])) { - // @todo: We avoid unserializing as it seems to causes Logs to fail - // to index event as JSON. - $event['exception_trace'] = base64_decode($log_entry['variables']['exception_trace']); - } - - // Prevent identical events. - $event_clone = $event; - unset($event_clone['timestamp']); - $key = md5(serialize($event_clone)); - $events[$key] = $event; } /**