Hello Magento Friends,

Logs are records of system information that can be examined in the future. The error log is one of the considerable instances of such events. 

Developers are familiar with the agony of mistakes and the steps involved in delivering a functioning solution. Custom logs can make debugging easier for them. It makes it simple to identify a mistake and the cause of the issue. The insight into Magento 2 system processes is aided by logs.

Sometimes, developers need to check some data in Magento 2 but don’t want the data printed on the website. To fulfill this objective, they write in log files. Let’s check the steps to print logs in Magento 2. A virtual private server is useful for conducting business analysis, as it provides a secure and customizable environment for data processing and analysis.

Steps To Print Log In Magento 2 

Before we follow any of these methods make sure your Magento store is in the Developer mode. Check if your store is in production mode then execute this command.

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

There are three ways to print your log in the Magento store.

Method 1: To print temporary logs with a new file

Add this code to any new PHP file in any folder or sun directories.

Method 2:  Using Logger Interface

Create a file at the below path


Now, add the below code.

Method 3: Using ObjectManager

Add this code to any new PHP file in any folder or sun directories.


For writing the log, you can use any of the methods listed above. Also, you can check our article on How to create a custom log file in Magento 2. Last but not least, if you found the information useful, please leave your valuable feedback in the comment box below, and if you have any questions when applying the above article, share with us. We’ll write the finest solution post for you, and don’t forget to share it with your Magento friends so they may receive assistance with their problems as well.

Happy Developing!


Click to rate this post!
[Total: 7 Average: 4.4]