Menu Close
    Start a Project Request quote Reading list Switch to dark mode

    Quickly Log in Custom File in Magento 2

    Hello, readers! In this article, I will teach you a very useful quick hack for Magento 2 developers. Here we will see how we can quickly log in a custom log file in Magento 2.

    As you may know you can log using Psr\Log\LoggerInterface. But it will log in either system.log or debug.log file based on the log level. You can also log to a custom file as mentioned in Magento2 Custom Log File Using Monolog blog. But it’s too much of work if you just want to log for debugging purpose.

    Logging to a custom file was very easy in Magento 1 days. In Magento 1, you can log using just one line of code in a custom file as mentioned below.

    So now let’s see, how we can achieve almost similar result in Magento 2.

    This code is pretty self-explanatory. It will create a log file named customfile.log under var/log/ folder and log ‘hello log’ in it.

    Thanks for reading the blog. Please share with fellow developers.

    . . .


    Add Your Comment

    Be the first to comment.

    Back to Top
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again