Monday, March 29, 2021

Steps to write to a log file while executing any application

Add the below lines of code to the executing function. This will generate a log file in the location specified. Here it is /var/log/test.log

 

$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('Your text message');//json_encode() if not text

No comments:

Post a Comment