Developers know the pain of errors and the process to deliver a working solution. Debugging can be made easier for them by custom logs. It helps to spot an error and the reason for it, easily. Logs contribute to the visibility into Magento 2 system processes.
Now if you want to learn how to print log in Magento 2, you’re at the right place! I have come up with 3 different methods to print log in Magento 2.
- Using Helper Data
- Using Logger Interface
- Using Object Manager
bin/magento config:set dev/debug/debug_logging 1
create file [Vendor]\[Module]\Helper\Data.php
public function __construct(Data $helperName)
$this->helper = $helperName;
$this->helper->printLog('msg for print');
Simply call Helper class method where you want to print the log :
create file [Vendor]\[Module]\[Path]\[fileName.php]