Sharing some useful tips, solutions and notes for Geeks.

Monday, February 3, 2020

Write log in Magento 2 using Zend library

Sometimes when we are troubleshooting, we might need to generate logs to see what values are returning in a special code.

For this we can use Zend library, which helps in creating the logs and thereby we can identify the things we need to know.

$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/customlog.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('Your text message');
If its an array, we can use

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

No comments: