class SalesforceLoggerSubscriber in Salesforce Suite 8.4
Same name and namespace in other branches
- 8.3 modules/salesforce_logger/src/EventSubscriber/SalesforceLoggerSubscriber.php \Drupal\salesforce_logger\EventSubscriber\SalesforceLoggerSubscriber
- 5.0.x modules/salesforce_logger/src/EventSubscriber/SalesforceLoggerSubscriber.php \Drupal\salesforce_logger\EventSubscriber\SalesforceLoggerSubscriber
Class SalesforceLoggerSubscriber.
@package Drupal\salesforce_logger
Hierarchy
- class \Drupal\salesforce_logger\EventSubscriber\SalesforceLoggerSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of SalesforceLoggerSubscriber
1 string reference to 'SalesforceLoggerSubscriber'
- salesforce_logger.services.yml in modules/
salesforce_logger/ salesforce_logger.services.yml - modules/salesforce_logger/salesforce_logger.services.yml
1 service uses SalesforceLoggerSubscriber
File
- modules/
salesforce_logger/ src/ EventSubscriber/ SalesforceLoggerSubscriber.php, line 17
Namespace
Drupal\salesforce_logger\EventSubscriberView source
class SalesforceLoggerSubscriber implements EventSubscriberInterface {
const EXCEPTION_MESSAGE_PLACEHOLDER = '%type: @message in %function (line %line of %file).';
/**
* Logger.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* Create a new Salesforce Logger Subscriber.
*
* @param \Psr\Log\LoggerInterface $logger
* The logger.
*/
public function __construct(LoggerInterface $logger) {
$this->logger = $logger;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events = [
SalesforceEvents::ERROR => 'salesforceException',
SalesforceEvents::WARNING => 'salesforceException',
SalesforceEvents::NOTICE => 'salesforceException',
];
return $events;
}
/**
* SalesforceException event callback.
*
* @param \Drupal\salesforce\Event\SalesforceExceptionEventInterface $event
* The event.
*/
public function salesforceException(SalesforceExceptionEventInterface $event) {
$log_level_setting = \Drupal::configFactory()
->get('salesforce_logger.settings')
->get('log_level');
$event_level = $event
->getLevel();
// Only log events whose log level is greater or equal to min log level
// setting.
if ($log_level_setting != SalesforceEvents::NOTICE) {
if ($log_level_setting == SalesforceEvents::ERROR && $event_level != RfcLogLevel::ERROR) {
return;
}
if ($log_level_setting == SalesforceEvents::WARNING && $event_level == RfcLogLevel::NOTICE) {
return;
}
}
$exception = $event
->getException();
if ($exception) {
$this->logger
->log($event
->getLevel(), self::EXCEPTION_MESSAGE_PLACEHOLDER, Error::decodeException($exception));
}
else {
$this->logger
->log($event
->getLevel(), $event
->getMessage(), $event
->getContext());
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SalesforceLoggerSubscriber:: |
protected | property | Logger. | |
SalesforceLoggerSubscriber:: |
constant | |||
SalesforceLoggerSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
SalesforceLoggerSubscriber:: |
public | function | SalesforceException event callback. | |
SalesforceLoggerSubscriber:: |
public | function | Create a new Salesforce Logger Subscriber. |