Skip to content

Commit

Permalink
добавлена возможность вести системный журнал
Browse files Browse the repository at this point in the history
  • Loading branch information
easterism committed Sep 12, 2016
1 parent f8976f0 commit 9cda601
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 50 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=5.2.11",
"php": ">=5.4.0",
"smottt/wideimage": ">=1.1.1",
"mpdf/mpdf": "5.7.4",
"components/jquery": "2.1.4",
"monolog/monolog": "1.17.*",
"monolog/monolog": "1.21.x",
"ext-mbstring": "*"
}
}
2 changes: 1 addition & 1 deletion html/default/style2.css
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ table td.homeTD {
margin: 0 65px 10px 10px;
}

/* css for Notice class */
/* css for Alert class */
.im-msg-red {
background-color: #f2dede;
width:96%;
Expand Down
4 changes: 2 additions & 2 deletions inc/classes/Alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function info($head, $explanation = '', $force = false) {
* @param string $explanation
* @param bool $force
*
* @return $this
* @return $this|void
*/
public function success($head, $explanation = '', $force = false) {
if ($force) {
Expand All @@ -161,7 +161,7 @@ public function success($head, $explanation = '', $force = false) {
* @param string $explanation
* @param bool $force
*
* @return $this
* @return $this|void
*/
public function warning($head, $explanation = '', $force = false) {
if ($force) {
Expand Down
5 changes: 3 additions & 2 deletions inc/classes/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function getInvoker() {
public function __get($k) {

//исключение для герета базы или кеша, выполняется всегда
if ($k == 'db' || $k == 'cache' || $k == 'translate') {
if ($k == 'db' || $k == 'cache' || $k == 'translate' || $k == 'log') {
return parent::__get($k);
}
//геттер для модели
Expand All @@ -91,7 +91,8 @@ public function __get($k) {

if (array_key_exists($k, $this->_p)) {
$v = $this->_p[$k];
} else {
}
else {
// Получение экземпляра класса для работы с правами пользователей
if ($k == 'acl') {
$v = $this->{$k} = Zend_Registry::getInstance()->get('acl');
Expand Down
50 changes: 33 additions & 17 deletions inc/classes/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __get($k) {
}
return $v;
}
// Получение перевода
// Получение экземпляра переводчика
if ($k == 'translate') {
if (array_key_exists($k, $this->_s)) {
$v = $this->_s[$k];
Expand All @@ -66,6 +66,16 @@ public function __get($k) {
}
return $v;
}
// Получение экземпляра логера
elseif ($k == 'log') {
if (array_key_exists($k, $this->_s)) {
$v = $this->_s[$k];
} else {
$v = new \Core2\Log();
$this->_s[$k] = $v;
}
return $v;
}
// Получение экземпляра модели текущего модуля
elseif (strpos($k, 'data') === 0) {
if (array_key_exists($k, $this->_s)) {
Expand Down Expand Up @@ -107,15 +117,17 @@ protected function establishConnection($database) {
return $db;
}

/**
* @param string $dbname
* @param string $username
* @param string $password
* @param string $host
* @param string $charset
* @param string $adapter
* @return Zend_Db_Adapter_Abstract
*/
/**
* Установка соединения с произвольной базой MySQL
* @param $dbname
* @param $username
* @param $password
* @param string $host
* @param string $charset
* @param string $adapter
*
* @return void|Zend_Db_Adapter_Abstract
*/
public function newConnector($dbname, $username, $password, $host = 'localhost', $charset = 'utf8', $adapter = 'Pdo_Mysql') {
$temp = array('host' => $host,
'username' => $username,
Expand All @@ -126,12 +138,13 @@ public function newConnector($dbname, $username, $password, $host = 'localhost',
try {
$db = Zend_Db::factory($adapter, $temp);
$db->getConnection();
} catch (Zend_Db_Adapter_Exception $e) {
Error::catchDbException($e);
} catch (Zend_Exception $e) {
Error::catchZendException($e);
}
return $db;
return $db;
} catch (Zend_Db_Adapter_Exception $e) {
Error::catchDbException($e);
} catch (Zend_Exception $e) {
Error::catchZendException($e);
}
return;
}

/**
Expand Down Expand Up @@ -231,7 +244,7 @@ public function logActivity($exclude = array()) {
isset($this->config->log->system->writer) && $this->config->log->system->writer == 'file'
) {
if (!$this->config->log->system->file) {
throw new Exception($this->traslate->tr('Не задан файл журнала'));
throw new Exception($this->traslate->tr('Не задан файл журнала запросов'));
}

$log = new \Core2\Log('access');
Expand Down Expand Up @@ -535,6 +548,9 @@ final public function getModule($module_id) {

}

/**
* Получение всех настроек системы
*/
final private function getAllSettings() {
$key = "all_settings_" . $this->config->database->params->dbname;
if (!($this->cache->test($key))) {
Expand Down
44 changes: 22 additions & 22 deletions inc/classes/Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@
Error::Exception("Отсутствует конфигурационный файл.");
}
$config = array(
'system' => array('name' => 'CORE'),
'include_path' => '',
'cache' => 'cache',
'temp' => getenv('TMP'),
'debug' => array('on' => false),
'database' => array(
'adapter' => 'Pdo_Mysql',
'params' => array(
'charset' => 'utf8',
'adapterNamespace' => 'Core_Db_Adapter'
),
'isDefaultTableAdapter' => true,
'profiler' => array(
'enabled' => false,
'class' => 'Zend_Db_Profiler_Firebug'
),
'caseFolding' => true,
'autoQuoteIdentifiers' => true,
'allowSerialization' => true,
'autoReconnectOnUnserialize' => true
)
'system' => array('name' => 'CORE'),
'include_path' => '',
'cache' => 'cache',
'temp' => getenv('TMP'),
'debug' => array('on' => false),
'database' => array(
'adapter' => 'Pdo_Mysql',
'params' => array(
'charset' => 'utf8',
'adapterNamespace' => 'Core_Db_Adapter'
),
'isDefaultTableAdapter' => true,
'profiler' => array(
'enabled' => false,
'class' => 'Zend_Db_Profiler_Firebug'
),
'caseFolding' => true,
'autoQuoteIdentifiers' => true,
'allowSerialization' => true,
'autoReconnectOnUnserialize' => true
)
);
// определяем путь к темповой папке
if (empty($config['temp'])) {
Expand Down Expand Up @@ -161,7 +161,7 @@ public function __construct() {
parent::__construct();

if (empty($_SERVER['HTTPS'])) {
if (isset($this->config->system) && ! empty($this->config->system->https)) {
if (isset($this->config->system) && !empty($this->config->system->https)) {
header('Location: https://' . $_SERVER['SERVER_NAME']);
}
}
Expand Down
40 changes: 36 additions & 4 deletions inc/classes/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogHandler;
use Monolog\Processor\WebProcessor;
use Monolog\Formatter\NormalizerFormatter;

/**
* Обеспечение журналирования запросов пользователей
Expand All @@ -15,8 +16,20 @@ class Log {
private $config;
private $writer;

public function __construct($name) {
$this->log = new Logger($name);
public function __construct($name = 'core2', $logfile = '') {
if ($name != 'access') {
$this->log = new Logger($_SERVER['SERVER_NAME'] . "." . $name);
$this->config = \Zend_Registry::getInstance()->get('core_config');
if ($this->config->log->system->file) {
$stream = new StreamHandler($this->config->log->system->file);
//$stream->setFormatter(new NormalizerFormatter());
$this->log->pushHandler($stream);
}

} elseif ($logfile) {
$this->log = new Logger($name);
$this->config = \Zend_Registry::getInstance()->get('config');
}
}

public function access($name) {
Expand All @@ -27,7 +40,6 @@ public function access($name) {

private function setWriter() {
if (!$this->writer) {
$this->config = \Zend_Registry::getInstance()->get('config');
if ($this->config->log->system->file) {
$this->log->pushHandler(new StreamHandler($this->config->log->system->file, Logger::INFO));
$this->writer = 'file';
Expand All @@ -39,7 +51,27 @@ private function setWriter() {
}

public function info($msg, $context = array()) {
$this->log->addInfo($msg, $context);
if (is_array($msg)) {
$context = $msg;
$msg = '-';
}
$this->log->info($msg, $context);
}

public function warning($msg, $context = array()) {
if (is_array($msg)) {
$context = $msg;
$msg = '-';
}
$this->log->warning($msg, $context);
}

public function debug($msg, $context = array()) {
if (is_array($msg)) {
$context = $msg;
$msg = '-';
}
$this->log->debug($msg, $context);
}

}

0 comments on commit 9cda601

Please sign in to comment.