Magento2 has different types of Exception handlers
StateException
InputException
InvalidEmailOrPasswordException
MailException
NotFoundException
ValidatorException
Etc.
All handler types and their classes exist in \vendor\magento\framework\Exception.
You need to choose the relevant Exception handler for your requirements and use that.
Magento 2 logging
$this->_logger->addDebug($message); // log location: var/log/system.log
$this->_logger->addInfo($message); // log location: var/log/system.log
$this->_logger->addNotice($message); // log location: var/log/system.log
$this->_logger->addError($message); // log location: var/log/system.log
$this->_logger->critical($e); // log location: var/log/system.log
StateException
InputException
InvalidEmailOrPasswordException
MailException
NotFoundException
ValidatorException
Etc.
All handler types and their classes exist in \vendor\magento\framework\Exception.
You need to choose the relevant Exception handler for your requirements and use that.
Magento 2 logging
$this->_logger->addDebug($message); // log location: var/log/system.log
$this->_logger->addInfo($message); // log location: var/log/system.log
$this->_logger->addNotice($message); // log location: var/log/system.log
$this->_logger->addError($message); // log location: var/log/system.log
$this->_logger->critical($e); // log location: var/log/system.log
protected $_logger;
public function __construct(
\Psr\Log\LoggerInterface $logger, //log injection
) {
$this->_logger = $logger;
}
public function someExampleMethod() {
$this->_logger->addDebug('some text or variable');
}
Comments
Post a Comment