I am trying to put log in observer

sales_order_save_after Whenever I put logger in the execute I can’t do any checkout it complains about guest checkout payment Is there any other way I could see the log

When I do var_dump it takes me to cart page from checkout because I am stopping the payment


2 Answers 2


Try Below Code:

Check LoggerInterface to debug

namespace Custom\Module\Observer;

use \Magento\Framework\Event\ObserverInterface;
use \Magento\Framework\Event\Observer;

class Index implements ObserverInterface
     protected $logger;

     public function __construct(
        \Psr\Log\LoggerInterface $logger
                    ) {
        $this->logger = $logger;
  public function execute(Observer $observer)

         $order = $observer->getEvent()->getOrder();
         // shipping address
         $shippingAddress = $order->getShippingAddress(); 
         $city = $shippingAddress->getCity();
         $country = $shippingAddress->getCountryId();


Log print below path:-


I hope so it's use full.

  • coreSession not been used anywhere is there any reason for that or is that just an accident you have added in the constructor? Oct 11, 2019 at 7:56
  • check I have updated my code @jibingeorge
    – Devidas
    Oct 11, 2019 at 8:00
  • for some reason to use coreSession
    – Devidas
    Oct 11, 2019 at 8:03

Try this one.

$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/custom.log');
$logger = new \Zend\Log\Logger();
$logger->info('=== Your Comment Here ===');
$logger->info('Print Your Value: '.$yourvariable);
$logger->info('=== Your Comment Here ===');
  • Thank you I will give this one a go too Oct 11, 2019 at 6:33

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