Magento 2

Add log magento 2

protected $logger;
public function __construct(\Psr\Log\LoggerInterface $logger)
{
    $this->logger = $logger;
}
You use debug, exception, system for psr logger for example
 
$this->logger->info($message);

$this->logger->debug($message); 

 

OR

 

In magento2, You can also write to the logs using the Zend library like below :

 

$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');

$logger = new \Zend\Log\Logger();

$logger->addWriter($writer);

$logger->info('Your text message');

You can also print PHP objects and arrays like below :

$logger->info(print_r($yourArray, true));

OR 

\Magento\Framework\App\ObjectManager::getInstance()

    ->get('Psr\Log\LoggerInterface')->debug('message');

0 Bình luận

Trở về
  • Magento plug-ins
  • Magento plug-ins

    Magento2 gave very good concept called Plugin   we can do what ever after and before core function and also we have...

  • HOW TO CREATE MENU IN MAGENTO 2 ADMIN
  • HOW TO CREATE MENU IN MAGENTO 2 ADMIN

    magento-2-admin- menu My previous tutorial show you how to create a simple module in Magento 2, learn more here: http://www.venustheme.com/how-to-create-magento-2-module/....