Would it be possible to add an alter hook and support for ignoring certain log entries?

For example, I want to log notices but not all notices, things like Updated entity user with ID 123.

It would be nice if we could do something like:

function mymodule_raven_log_alter(&$level, &$message, &$context) {
  // Ignore Rest updates.
  if ($context['channel'] === 'rest' && $message === 'Updated entity %type with ID %id.') {
    $context['ignore'] = TRUE;
  }
}

Then we could add something like this in Raven.php:

public function log($level, $message, array $context = []) {
  if (!$this->client) {
    // Sad raven.
    return;
  }

  // New stuff here...
  $this->moduleHandler->alter('raven_log', $level, $message, $context);
  if (!empty($context['ignore'])) {
    return;
  }

  if (empty($this->config->get('log_levels')[$level + 1])) {
    return;
  }

Comments

joelstein created an issue. See original summary.

joelstein’s picture

Status: Active » Needs review

Here's a patch which adds this functionality and also a raven.api.php file which documents it.

joelstein’s picture

StatusFileSize
new1.64 KB

Oops, forgot the patch!

mfb’s picture

I would like to add this, but I'd like to make the functionality more similar to that provided in the Drupal 7 version of the module (e.g. use 'process' rather than 'ignore') to make any site upgrades easier.

mfb’s picture

StatusFileSize
new2.46 KB

Refactored this a bit so that the entire $data array passed to Raven client can be altered by other modules - I think this would make it more generally useful.

mfb’s picture

StatusFileSize
new6.02 KB

Added some tests.

  • mfb committed c597210 on 8.x-2.x
    Issue #2978946 by joelstein, mfb: Add alter hook so we can ignore...
mfb’s picture

Status: Needs review » Fixed

Please try out the new hook and update this issue if you find any trouble. Thanks! :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.