Skip to content

Instantly share code, notes, and snippets.

@jlnarvaez
Last active July 27, 2023 09:01
Show Gist options
  • Save jlnarvaez/90fee1c1bebe09d67ae4695658f3aedb to your computer and use it in GitHub Desktop.
Save jlnarvaez/90fee1c1bebe09d67ae4695658f3aedb to your computer and use it in GitHub Desktop.
Magento 2 Custom Log (for Development purposes)
<?php
/**
* This snippet is useful to debug in production environments.
* DON'T USE THIS CODE TO LOG IN YOUR MODULES.
* To create a custom log check Magento official documentation
* (https://devdocs.magento.com/guides/v2.4/config-guide/log/custom-logger-handler.html)
*/
// Custom Log for Magento v2.3 or <
(new \Zend\Log\Logger())->addWriter((new \Zend\Log\Writer\Stream(BP . '/var/log/pruebas.log')))->info('Simple Text Log');
// Custom Log for Magento 2.4 or >
(new \Zend_Log())->addWriter((new \Zend_Log_Writer_Stream(BP . '/var/log/pruebas.log')))->info('Simple Text Log');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment