March 2019
Intermediate to advanced
580 pages
15h 3m
English
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 now:
/** * {@inheritdoc} */public function log($level, $message, array $context = array()) { if ($level !== RfcLogLevel::ERROR) { return; } $to = $this->configFactory->get('system.site')->get('mail'); $langcode = $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, $langcode, ['message' => $markup]);}
First of all, we said that we ...