I want to write custom log in third party module, how can I achieve this by using Magento default classes and log functions.

I tried many solutions but no luck on third party module. I need to write own file in log directory.

Please help me if anyone know how to achieve this?

1 Answer 1


Use below code to generate log file

$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/custom.log');
$logger = new \Zend\Log\Logger();

$logger->info('Test log here');
  • Okay thanks for your quick response on this, I will try and get back to you.
    – Jdprasad V
    Aug 7, 2019 at 10:32
  • Thank you so much, this is working perfectly.
    – Jdprasad V
    Aug 7, 2019 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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