Bhaveshpp

Professional Magento Developr - Healp eachother to grow

Magento2: How to use custom log file?

27 May 2021 » magento2

code for test log

$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('Simple Text Log'); // Simple Text Log
$logger->info('Array Log'.print_r($option, true)); // Array Log

short code for log

# Place logs in var/log/debug.log 
$logger = \Magento\Framework\App\ObjectManager::getInstance()->get(\Psr\Log\LoggerInterface::class);
$logger->info('Price');
$logger->log(100,print_r($items->getData(),true));
public function lol($lol)
    {
        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');
        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);
        $logger->info('Simple Text Log'); // Simple Text Log
        $logger->info('AT : '. $lol); // Simple Text Log
        // $this->lol(__FILE__."::".__LINE__);
    }