*/ abstract class Mage_ImportExport_Model_Abstract extends Varien_Object { /** * Enable loging * * @var boolean */ protected $_debugMode = false; /** * Loger instance * @var Mage_Core_Model_Log_Adapter */ protected $_logInstance; /** * Fields that should be replaced in debug with '***' * * @var array */ protected $_debugReplacePrivateDataKeys = array(); /** * Contains all log information * * @var array */ protected $_logTrace = array(); /** * Log debug data to file. * Log file dir: var/log/import_export/%Y/%m/%d/%time%_%operation_type%_%entity_type%.log * * @param mixed $debugData * @return Mage_ImportExport_Model_Abstract */ public function addLogComment($debugData) { if (is_array($debugData)) { $this->_logTrace = array_merge($this->_logTrace, $debugData); } else { $this->_logTrace[] = $debugData; } if (!$this->_debugMode) { return $this; } if (!$this->_logInstance) { $dirName = date('Y' . DS .'m' . DS .'d' . DS); $fileName = join('_', array( str_replace(':', '-', $this->getRunAt()), $this->getScheduledOperationId(), $this->getOperationType(), $this->getEntity() )); $dirPath = Mage::getBaseDir('var') . DS . Mage_ImportExport_Model_Scheduled_Operation::LOG_DIRECTORY . $dirName; if (!is_dir($dirPath)) { mkdir($dirPath, 0750, true); } $fileName = substr(strstr(Mage_ImportExport_Model_Scheduled_Operation::LOG_DIRECTORY, DS), 1) . $dirName . $fileName . '.log'; $this->_logInstance = Mage::getModel('core/log_adapter', $fileName) ->setFilterDataKeys($this->_debugReplacePrivateDataKeys); } $this->_logInstance->log($debugData); return $this; } /** * Return human readable debug trace. * * @return array */ public function getFormatedLogTrace() { $trace = ''; $lineNumber = 1; foreach ($this->_logTrace as &$info) { $trace .= $lineNumber++ . ': ' . $info . "\n"; } return $trace; } }