Magento2 Logging The Information

In Magento2, we can use the below public method in any of your class for the debug purpose or logging the information as per our requiremnts. This is not a standard way but you can use this for quick and needy purpose.


public function log($message) {
  $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');
  $logger = new \Zend\Log\Logger();
  $logger->addWriter($writer);
  $logger->info($message);
}

Leave a Reply