Skip to content

Instantly share code, notes, and snippets.

@DominicWatts
Last active May 4, 2022 15:25
Show Gist options
  • Save DominicWatts/6a49be6a99752e8b09cf1c56862b295c to your computer and use it in GitHub Desktop.
Save DominicWatts/6a49be6a99752e8b09cf1c56862b295c to your computer and use it in GitHub Desktop.
Magento 2 Write to Custom Log Files
// quick 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');
// 2.4.3 + syntax
$writer = new \Zend_Log_Writer_Stream(BP . '/var/log/test.log');
$logger = new \Zend_Log();
$logger->addWriter($writer);
$logger->info('Your text message');
$logger->info(print_r($yourArray, true));
\Magento\Framework\App\ObjectManager::getInstance()
->get(\Psr\Log\LoggerInterface::class)->debug('message');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment