1

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

paj
  • 5,785
  • 5
  • 21
  • 43
Jack Brooks
  • 319
  • 4
  • 15

2 Answers2

6

Try Below Code:

Check LoggerInterface to debug

<?php
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-&gt;logger = $logger;
}

public function execute(Observer $observer) {

     $order = $observer-&gt;getEvent()-&gt;getOrder();
     // shipping address
     $shippingAddress = $order-&gt;getShippingAddress(); 
     $city = $shippingAddress-&gt;getCity();
     $country = $shippingAddress-&gt;getCountryId();
     $this-&gt;logger-&gt;info(&quot;shippingAddress=&gt;&quot;.$country.&quot;&lt;&quot;);
     $this-&gt;logger-&gt;info(&quot;shippingAddress=&gt;&quot;.$city.&quot;&lt;&quot;);

    }

}

Log print below path:-

../var/log/system.log

I hope so it's use full.

Devidas
  • 3,358
  • 1
  • 27
  • 61
0

Try this one.

$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/custom.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('=== Your Comment Here ===');
$logger->info('Print Your Value: '.$yourvariable);
$logger->info('=== Your Comment Here ===');
Aniket Prajapati
  • 342
  • 3
  • 17