Menu Close
    Hire us Request quote Reading list Switch to dark mode

    Create a custom log file in Magento 2 using Monolog and logging data into it.

    Hello everyone, Today we will learn to create a custom log file programmatically and log data into the custom log file.

    First of all we need to create handlers and loggers for custom log file. For that, create a Logger.php class in Logger folder in your custom Module as shown below-

    After this, Create Handler class, in which we will define the custom Log file name as shown below-

    Last step is to define the monolog in di.xml in etc folder of your custom Module –

    This is it, now just use the logger in your Magento 2 file, to print the logs in the custom created log file with the following code-

    Now you can find the above printed data in var/log/customLog.log file.

    You can use this for logging any required data in your custom Module.

    This is all for now, I ll be back soon.

    . . .


    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 received your message and our expert will get back to you shortly.
    Send Again