use magento logger to log errors code example
Example 1: magento 2 custom logging
$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('Your text message');
Example 2: log magento 1
Mage::log('message',null,'logfile.log',true);