Magento2

How to Print Log in Magento 2?

How to Print Log in Magento 2_

Logs in Magento 2 consist the system information for the future analysis.

To enable the debug mode go to Stores -> Configuration -> Advanced -> Developer -> Debug -> Set ‘Yes’ to Log to file.

Also make sure Magento store is in developer mode. If Magento store is in Production Mode then need run the below command.

php bin/magento config:set dev/debug/debug_logging 1

Below are the Methods to print Log in Magento 2.

Method 1 : Using Helper Data

File : app/code/V4U/Helloworld/Helper/Data.php

Now you can call that Helper class where you want to print log.

File : app/code/[Vendor][Module][Path][fileName.php]

You can review log on following path : var/log/CustomLog.log

Method 2 : Using Logger Interface (Factory Method)

You can add Logger Interface where you want to print log.

File : app/code/[Vendor][Module][Path][fileName.php]

Method 3 : Using ObjectManager

For var\log\system.log

For var\log\debug.log

Method 4 : Temporary print log with new file

You can implement any above method for debugging the code.

🙂 Happy Coding. Keep Liking & Sharing 💻

Tagged , ,