Today we will be talking about how to work with Magento 2 log. There is a different type of log you can log with Magento 2. For example debug log, information log, and other logs too. so let start with our log type.
A simple example of how to inject the logger class.
protected $logger;
public function __construct(\Psr\Log\LoggerInterface $logger)
{
$this->logger = $logger;
}
public function __construct(\Psr\Log\LoggerInterface $logger)
{
$this->logger = $logger;
}
Debug Log Method
$this->_logger->addDebug($message);
log location: var/log/system.log
Info Log Method
$this->_logger->addInfo($message);
log location: var/log/exception.log
Notice Log Method
$this->_logger->addNotice($message);
log location: var/log/exception.log
Error Log Method
$this->_logger->addError($message);
log location: var/log/exception.log
Critical or Exception Log Method
$this->_logger->critical($message);
log location: var/log/exception.log