protected function _write($event) { $ip = Zend_Controller_Action_HelperBroker::getStaticHelper('Currentip'); $event['ip'] = $ip->getCurrentIp(); $event['created_by'] = Zend_Auth::getInstance()->getIdentity()->id; parent::_write($event); }
/** * Class constructor * * @param string $filename Filename */ public function __construct($filename) { $resource = Mage::getSingleton('core/resource'); $this->_db = $resource->getConnection('core_write'); $this->_table = $resource->getTableName('firegento_logger/db_entry'); $this->_columnMap = array('severity' => 'priority', 'message' => 'message'); parent::__construct($this->_db, $this->_table, $this->_columnMap); }
protected function _write($event) { $ip = Zend_Controller_Action_HelperBroker::getStaticHelper('Currentip'); $event['ip_client'] = $ip->getCurrentIp(); $event['ip_host'] = $_SERVER['SERVER_ADDR']; $event['created_by'] = Zend_Auth::getInstance()->getIdentity()->id; $event['id_branch'] = Zend_Auth::getInstance()->getIdentity()->id_branch; $event['request_headers'] = Zend_Json::encode(getallheaders()); $event['url'] = 'http' . (empty($_SERVER['HTTPS']) ? '' : 's') . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; $event['request_parameters'] = Zend_Json::encode($_REQUEST); $event['request_hash'] = $this->getRequestHash(); parent::_write($event); }
public function write($event) { if ($this->_db === null) { throw new Zend_Log_Exception('Database adapter is null'); } if ($this->_table === null) { throw new Zend_Log_Exception('Db table is null'); } $dataToInsert = array(); if ($this->_columnMap === null) { $dataToInsert = $event; } else { $dataToInsert = array(); foreach ($this->_columnMap as $columnName => $fieldKey) { $dataToInsert[$columnName] = $event[$fieldKey]; } } // Sprawdzamy czy możemy zrobić update zamiast insertu. $dataToUpdate = array(); if ($event['event_code'] == 'customerSynchronize') { $session = new Logic_Synchronizer_Session(); $id = $session->getLastLogId(); if ($id && ($row = $this->_table->findOne($id))) { $columnMapForUpdate = $row->getLogColumnMappingForUpdate(); if (count($columnMapForUpdate) > 0) { foreach ($columnMapForUpdate as $columnName => $fieldKey) { $dataToUpdate[$columnName] = $event[$fieldKey]; } $row->updateColumnsMappedForUpdate($dataToUpdate); $row->save(); return; } } $id = $this->_table->insert($dataToInsert); $session->setLastLogId($id); } else { parent::write($event); } }
/** * Load the configuration files into the Zend registry. * * @return Zend_Config_Ini configuration file * @throws Zend_Exception */ protected function _initConfig() { // init language $configGlobal = new Zend_Config_Ini(APPLICATION_CONFIG, 'global', true); if (isset($_COOKIE[MIDAS_LANGUAGE_COOKIE_NAME])) { $configGlobal->application->lang = $_COOKIE[MIDAS_LANGUAGE_COOKIE_NAME]; } if (isset($_GET['lang'])) { $language = $_GET['lang']; if ($language !== 'en' && $language !== 'fr') { $language = 'en'; } $configGlobal->application->lang = $language; $date = new DateTime(); $interval = new DateInterval('P1M'); setcookie(MIDAS_LANGUAGE_COOKIE_NAME, $language, $date->add($interval)->getTimestamp(), '/', !empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'], (int) $configGlobal->get('cookie_secure', 1) === 1, true); } Zend_Registry::set('configGlobal', $configGlobal); $configCore = new Zend_Config_Ini(CORE_CONFIG, 'global', true); Zend_Registry::set('configCore', $configCore); // check if internationalization enabled if (isset($configCore->internationalization) && $configCore->internationalization == '0') { $configGlobal->application->lang = 'en'; } $config = new Zend_Config_Ini(APPLICATION_CONFIG, $configGlobal->environment, true); Zend_Registry::set('config', $config); date_default_timezone_set($configGlobal->default->timezone); // InitDatabase $configDatabase = new Zend_Config_Ini(DATABASE_CONFIG, $configGlobal->environment, true); if (empty($configDatabase->database->params->driver_options)) { $driverOptions = array(); } else { $driverOptions = $configDatabase->database->params->driver_options->toArray(); } if ($configDatabase->database->adapter == 'PDO_SQLITE') { $params = array('dbname' => $configDatabase->database->params->dbname, 'driver_options' => $driverOptions); } else { if ($configDatabase->database->adapter == 'PDO_MYSQL') { $driverOptions[PDO::MYSQL_ATTR_USE_BUFFERED_QUERY] = true; } $params = array('dbname' => $configDatabase->database->params->dbname, 'username' => $configDatabase->database->params->username, 'password' => $configDatabase->database->params->password, 'driver_options' => $driverOptions); if (empty($configDatabase->database->params->unix_socket)) { $params['host'] = $configDatabase->database->params->host; $params['port'] = $configDatabase->database->params->port; } else { $params['unix_socket'] = $configDatabase->database->params->unix_socket; } } $db = Zend_Db::factory($configDatabase->database->adapter, $params); Zend_Db_Table::setDefaultAdapter($db); Zend_Registry::set('dbAdapter', $db); Zend_Registry::set('configDatabase', $configDatabase); // Init log if ($configGlobal->environment == 'production') { Zend_Loader_Autoloader::getInstance()->suppressNotFoundWarnings(true); $priority = Zend_Log::WARN; } else { Zend_Loader_Autoloader::getInstance()->suppressNotFoundWarnings(false); $priority = Zend_Log::DEBUG; } if (is_writable(LOGS_PATH)) { $stream = LOGS_PATH . '/' . $configGlobal->environment . '.log'; $logger = Zend_Log::factory(array(array('writerName' => 'Stream', 'writerParams' => array('stream' => $stream), 'formatterName' => 'Simple', 'filterName' => 'Priority', 'filterParams' => array('priority' => $priority)))); } else { $logger = Zend_Log::factory(array(array('writerName' => 'Syslog', 'formatterName' => 'Simple', 'filterName' => 'Priority', 'filterParams' => array('priority' => $priority)))); } if (file_exists(LOCAL_CONFIGS_PATH . '/database.local.ini')) { $columnMapping = array('priority' => 'priority', 'message' => 'message', 'module' => 'module'); $writer = new Zend_Log_Writer_Db($db, 'errorlog', $columnMapping); if ($configGlobal->environment == 'production') { $priority = Zend_Log::INFO; } else { $priority = Zend_Log::DEBUG; } $filter = new Zend_Log_Filter_Priority($priority); $writer->addFilter($filter); $logger->addWriter($writer); } $logger->setEventItem('module', 'core'); $logger->registerErrorHandler(); Zend_Registry::set('logger', $logger); // Init error handler require_once BASE_PATH . '/core/controllers/components/NotifyErrorComponent.php'; $notifyErrorComponent = new NotifyErrorComponent(); ini_set('display_errors', 0); register_shutdown_function(array($notifyErrorComponent, 'fatalError'), $logger); set_error_handler(array($notifyErrorComponent, 'warningError'), E_NOTICE | E_WARNING); return $config; }
/** * Sets the given Zend_Log object into the internal log property. * If no log given, a new instance with the internal configuration will be created. * @param Enlight_Components_Log|Zend_Log $log */ public function setResource(Zend_Log $log = null) { if ($log === null) { $log = new Enlight_Components_Log(); $log->setEventItem('date', Zend_Date::now()); $log->addWriter(new Zend_Log_Writer_Null()); $config = $this->Config(); if(!empty($config->logDb)) { $writer = Zend_Log_Writer_Db::factory(array( 'db' => Shopware()->Db(), 'table' => 's_core_log', 'columnmap' => array( 'type' => 'priority', 'key' => 'priorityName', 'text' => 'message', 'date' => 'date', 'ip_address' => 'remote_address', 'user_agent' => 'user_agent', ) )); $writer->addFilter(Enlight_Components_Log::WARN); $log->addWriter($writer); } if(!empty($config->logMail)) { $mail = new Enlight_Components_Mail(); $mail->addTo(Shopware()->Config()->Mail); $writer = new Zend_Log_Writer_Mail($mail); $writer->setSubjectPrependText('Fehler im Shop "'.Shopware()->Config()->Shopname.'" aufgetreten!'); $writer->addFilter(Enlight_Components_Log::WARN); $log->addWriter($writer); } } $this->log = $log; }
protected function addDbWriterToLogger(Zend_Log $logger, $config) { if (!(isset($config->active) && $config->active == 1)) { return; } $this->bootstrap('db'); $dbLogWriter = new Zend_Log_Writer_Db(Registry::getDbAdapter(), $config->table_name, array('websiteid' => 'websiteid', 'id' => 'id', 'name' => 'name', 'additionalinfo' => 'additionalinfo', 'timestamp' => 'timestamp', 'userlogin' => 'userlogin', 'action' => 'message')); if (isset($config->level)) { $dbLogWriter->addFilter((int) $config->level); } $logger->addWriter($dbLogWriter); }
/** * Write a message to the log. * * @param array $event event data * @return void * @throws Zend_Log_Exception */ protected function _write($event) { $config = Zend_Registry::get('config'); $isLogMsg = (bool) $config['logging']['log']['enable']; $isLogStat = (bool) $config['logging']['statistics']['enable']; $isLogEx = (bool) $config['logging']['exeption']['enable']; // Проверим возможность логирования if ($this->_table == 'log_msg' && !$isLogMsg) { return; } elseif ($this->_table == 'log_stat' && !$isLogStat) { return; } elseif ($this->_table == 'log_error' && !$isLogEx) { return; } // Удалим лишние записи if ($this->_max_rows && $this->_max_rows !== -1) { $select = $this->_db->select(); $select->from($this->_table, 'count(*)'); $count_rows = (int) $this->_db->fetchOne($select); if ($count_rows >= $this->_max_rows) { // Получим массив ids для удаления строк в таблице $limit = $count_rows - $this->_max_rows; $limit++; $select = $this->_db->select(); $select->from($this->_table, 'id'); $select->limit($limit, 0); $row_ids = $this->_db->fetchCol($select); // Удалим строки из таблицы foreach ($row_ids as $id) { $this->_db->delete($this->_table, 'id=' . $id); } } } // Запишем событие в лог parent::_write($event); }