We wanted to use our MailLogger to send out an email whenever we are logging an error. So let's go back to our class and add this logic.
This is what our log() method can look like:
/** * {@inheritdoc} */ public function log($level, $message, array $context = array()) { if ($level !== RfcLogLevel::ERROR) { return; } $to = $this->configFactory->get('system.site')->get('mail'); $langode = $this->configFactory->get('system.site')->get('langcode'); $variables = $this->parser->parseMessagePlaceholders($message, $context); $markup = new FormattableMarkup($message, $variables); \Drupal::service('plugin.manager.mail')->mail('hello_world', 'hello_world_log', $to, $langode, ['message' => $markup]); }
First of all, we stated that we ...