3

By the way, I hope you won't judge the roughness of this answer, just something quick I wanted to get out there :)

How would I be able to log all events magento dispatches in the order of execution?

3

Add this to vendor/magento/framework/event/invoker/invokerdefault::dispatch

public function dispatch(array $configuration, Observer $observer)
        {
            \Magento\Framework\App\ObjectManager::getInstance()
                ->get('Psr\Log\LoggerInterface')->debug($observer
                ->getEvent()->getName());
  • I have tried the above code..with if($observer->getEvent()->getName() == "sales_model_service_quote_submit_success"){ \Magento\Framework\App\ObjectManager::getInstance() ->get('Psr\Log\LoggerInterface')->debug($observer->getName()); } . but observer name seems to be empty. – Haritha Jul 19 '17 at 6:56
  • You are using "$observer->getName()‌​", try getting the event: $observer->getEvent()->getName() – Olavi Sau Jul 19 '17 at 7:05
  • $observer->getEvent()->getName() gives me event name. but need the observer names of that particular event. – Haritha Jul 19 '17 at 7:12
  • Try this (new ReflectionClass($observer))->getProperties() and see what's inside the observer. I must note, I haven't worked with magento for a while, asking a coworker (if you are working) might be more productive :D If that doesn't work, I'm not sure about this ... just a wild guess I think the event might hold the observer you want, thus $observer->getEvent()->getObserver()->getName()... just guessing – Olavi Sau Jul 19 '17 at 7:23
  • Also if you have the event name, you can check all the observers by running a search on your project files, use the event name as the search query and put a var_dump into the observers codes. Example event declaration in events.xml <event name="my_module_event_before"> <observer name="myObserverName" instance="MyCompany\MyModule\Observer\MyObserver" /> </event> – Olavi Sau Jul 19 '17 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.