Monday, November 16, 2015

How we can print array variable in log file of Magento 2 ?

In Magento 1.x, it was possible using Mage::log(print_r($arr, 1), null, 'logfile.log');

Consider following is your class file. 

class abc extends xyz
{
    protected $_logger;

    public function __construct(\Psr\Log\LoggerInterface $logger) {
        $this->_logger = $logger;
    }

 
     private function getValuesAsHtmlList(\Magento\Framework\Object $object) {
        $options = $this->getOptions($object);
//        $this->_logger->log(100,null,$options);
        $this->_logger->log(100,print_r($a,true)); //alternate method to print array as in structure form.
    }
 }

Now,open /var/debug.log file and check.

No comments:

Post a Comment