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

Allows to alter an event and allow to stop sending it as well #20

Open
wants to merge 2 commits into
base: 8.x-1.x
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions logs_http.api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/**
* @file
* Documents API functions for logs_http module.
*/

/**
* Alter the event which is going to be sent to the log service.
*
* Additionally you can stop sending an event to the log service by setting
* $event['send'] to FALSE. Useful for local environments, where this
* feature needs to be disabled.
*/
function hook_logs_http_event_alter(&$event) {
if (Settings::get('environment') == 'local') {
$event['send'] = FALSE;
}
}
12 changes: 12 additions & 0 deletions logs_http.module
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ function logs_http_shutdown() {

// Send events to logs.
foreach ($events as $event) {
// Allows to alter an event by adding new properties, or completely disable
// sending an event to the log service by setting $event['send'] = FALSE;
$event['send'] = TRUE;
$module_handler = \Drupal::moduleHandler();
$module_handler->alter('logs_http_event', $event);

// If event does not want be sent, continue with the next one.
if (empty($event['send'])) {
continue;
}

unset($event['send']);
$client = \Drupal::httpClient();

try {
Expand Down