How I can create my own custom logger in magento2 ?

In Magento 1, We simply write own custom log with the following code:

Mage::log("Log Message", null, "log_file.log"); 
  • $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/mylog.log'); $logger = new \Zend\Log\Logger(); $logger->addWriter($writer); $logger->info("Your comment ".$variables);
    – Manish
    Commented May 7, 2016 at 11:05
  • I think the right duplicate question/answer is here: magento.stackexchange.com/questions/75935/… Commented Jun 30, 2017 at 8:14

1 Answer 1


For logging OR creating log file, you should use class "Magento\Framework\Logger\Monolog".

For more see here : http://inchoo.net/magento-2/magento-2-logging/

Not the answer you're looking for? Browse other questions tagged or ask your own question.