Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally submit some debugging details once for each request #5

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions logs_http.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
32 changes: 32 additions & 0 deletions logs_http.module
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,45 @@ 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;
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,
'COOKIE' => $_COOKIE,
);
$events['debugging'] = $debugging_event;
}
}
}

/**
* Get the registered events from the static cache.
*
Expand Down