How to get Magento 2 events/observers
You can get the list of events/observers in Magento 2 in the \Magento\Framework\Event\Manager::dispatch() method. Since there is no access to the logger, you will have to add a logger instance in the constructor:
1 2 3 4 5 6 7 8 9 10 11 |
$protected $logger; public function __construct( InvokerInterface $invoker, ConfigInterface $eventConfig, \Psr\Log\LoggerInterface $logger ) { $this->_invoker = $invoker; $this->_eventConfig = $eventConfig; $this->logger = $logger; } |
Now, call in the dispatch method:
1 |
$this->logger->info($message); |
Instead of info you can use \Psr\Log\LoggerInterface methods.
Source (
More Magento 2 tips from the Cookbook