I am trying to print order details in Log /return JSON result when a new order is placed. Nothing is printing in System.log or in exception.log,

Please check my code below, Let me know where I am doing wrong.


<?php /**
* Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details.
\Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Autosynch_Sale',


<?xml version="1.0"?>
* Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details.
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Autosynch_Sale" setup_version="0.0.1">


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="checkout_submit_all_after">
        <observer name="modulename_sales_order_place_after" instance="Autosynch\Sale\Observer\OrderPlaceAfter" />


   namespace Autosynch\Sale\Observer;

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

    class OrderPlaceAfter implements ObserverInterface
        protected $_logger;

         * @param \Psr\Log\LoggerInterface $_logger

        public function __construct(
            \Psr\Log\LoggerInterface $_logger
            $this->_logger = $_logger;

        public function execute(Observer $observer)
            $order = $observer->getEvent()->getOrder();



You have created to composer.json for your module.

Also, observer definition file name is the wrong event.xml, it should be events.xml

second, to print an array, you should use


If you enable developer mode or default mode then might be log print is not working

for log print, you can try to use a custom log file

$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/order.log');
$logger = new \Zend\Log\Logger();
$logger->info('Your text message');
$logger->info(print_r($order->getData(), true));

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.