diff options
author | Benaka Moorthi <benaka.moorthi@gmail.com> | 2013-09-23 12:18:19 +0400 |
---|---|---|
committer | Benaka Moorthi <benaka.moorthi@gmail.com> | 2013-09-23 12:18:19 +0400 |
commit | da38169ad193948602f9b4d6f93c1f77cacac344 (patch) | |
tree | 58afda9216c6cf7c1acc4554133962bd83862a3a /core | |
parent | 809ca913e379113e4c64e9fa82a0d8f17fe8fca6 (diff) |
Made changes.
Diffstat (limited to 'core')
-rw-r--r-- | core/ExceptionHandler.php | 4 | ||||
-rw-r--r-- | core/FrontController.php | 1 | ||||
-rw-r--r-- | core/Log.php | 47 | ||||
-rw-r--r-- | core/Piwik.php | 1 |
4 files changed, 31 insertions, 22 deletions
diff --git a/core/ExceptionHandler.php b/core/ExceptionHandler.php index c6d4f1d22b..ac632f1660 100644 --- a/core/ExceptionHandler.php +++ b/core/ExceptionHandler.php @@ -10,7 +10,6 @@ */ use Piwik\Piwik; use Piwik\Log; -use Piwik\Log\ExceptionScreenFormatter; use Piwik\FrontController; /** @@ -22,9 +21,8 @@ use Piwik\FrontController; function Piwik_ExceptionHandler(Exception $exception) { try { - \Zend_Registry::get('logger_exception')->logEvent($exception); + Log::e("%s (%s): %s", array($exception->getFile(), $exception->getLine(), $exception->getMessage())); // TODO add backtrace? } catch (Exception $e) { - if (FrontController::shouldRethrowException()) { throw $exception; } diff --git a/core/FrontController.php b/core/FrontController.php index 232680d680..d521b9a2f5 100644 --- a/core/FrontController.php +++ b/core/FrontController.php @@ -13,7 +13,6 @@ namespace Piwik; use Exception; use Piwik\API\Request; use Piwik\API\ResponseBuilder; -use Piwik\Log; use Piwik\Session; use Zend_Registry; diff --git a/core/Log.php b/core/Log.php index feeaf92ef4..6533473bfa 100644 --- a/core/Log.php +++ b/core/Log.php @@ -141,16 +141,16 @@ class Log $writer = false; if ($writerName == 'file') { - $writer = function ($pluginName, $datetime, $message) use ($self) { - $self->logToFile($this->formatMessage($pluginName, $datetime, $message)); + $writer = function ($level, $pluginName, $datetime, $message) use ($self) { + $self->logToFile($this->formatMessage($level, $pluginName, $datetime, $message)); }; } else if ($writerName == 'screen') { $writer = function ($pluginName, $datetime, $message) use ($self) { - $self->logToScreen($this->formatMessage($pluginName, $datetime, $message)); + $self->logToScreen($this->formatMessage($level, $pluginName, $datetime, $message)); }; } else if ($writerName == 'db') { - $writer = function ($pluginName, $datetime, $message) use ($self) { - $self->logToDatabase($pluginName, $datetime, $message); + $writer = function ($level, $pluginName, $datetime, $message) use ($self) { + $self->logToDatabase($level, $pluginName, $datetime, $message); }; } return $writer; @@ -166,22 +166,22 @@ class Log echo $message . "\n"; } - private function logToDatabase($pluginName, $datetime, $message) + private function logToDatabase(logToDatabase$pluginName, $datetime, $message) { $sql = "INSERT INTO " . Common::prefixTable($this->logToDatabaseTable) - . " (plugin, time, message)" - . " VALUES (?, ?, ?)"; - Db::query($sql, array($pluginName, $datetime, $message)); + . " (plugin, time, level, message)" + . " VALUES (?, ?, ?, ?)"; + Db::query($sql, array($pluginName, $datetime, $level, $message)); } /** * TODO */ - public function log($level, $pluginName, $message, $sprintfParams = array()) + private function doLog($level, $pluginName, $message, $sprintfParams = array()) { if ($this->shouldLoggerLog($level)) { $datetime = date("Y-m-d H:i:s"); - $message = sprintf($message, $sprintfParams); + $message = vsprintf($message, $sprintfParams); $this->writeMessage($pluginName, $message, $datetime); } @@ -190,11 +190,11 @@ class Log /** * TODO */ - private function formatMessage($pluginName, $message, $datetime) + private function formatMessage($level, $pluginName, $message, $datetime) { return str_replace( - array("%pluginName%", "%message%", "%datetime%"), - array($pluginName, $message, $datetime), + array("%pluginName%", "%message%", "%datetime%", "%level%"), + array($pluginName, $message, $datetime, $this->getStringLevel($level)), $this->logMessageFormat ); } @@ -202,10 +202,10 @@ class Log /** * TODO */ - private function writeMessage($pluginName, $datetime, $message) + private function writeMessage($level, $pluginName, $datetime, $message) { foreach ($this->writers as $writer) { - $writer($pluginName, $datetime, $message); + $writer($level, $pluginName, $datetime, $message); } } @@ -214,7 +214,7 @@ class Log */ public static function log($level, $pluginName, $message, $sprintfParams = array()) { - self::getInstance()->log($level, $pluginName, $message, $sprintfParams); + self::getInstance()->doLog($level, $pluginName, $message, $sprintfParams); } /** @@ -306,4 +306,17 @@ class Log return -1; } } + + private function getStringLevel($level) + { + static $levelToName = array( + self::NONE => 'NONE', + self::ERROR => 'ERROR', + self::WARN => 'WARN', + self::INFO => 'INFO', + self::DEBUG => 'DEBUG', + self::VERBOSE => 'VERBOSE' + ); + return $levelToName[$level]; + } }
\ No newline at end of file diff --git a/core/Piwik.php b/core/Piwik.php index 7d30a3a04c..2bbed48863 100644 --- a/core/Piwik.php +++ b/core/Piwik.php @@ -14,7 +14,6 @@ use Exception; use Piwik\Db\Adapter; use Piwik\Db\Schema; use Piwik\Db; -use Piwik\Log\ScreenFormatter; use Piwik\Plugin; use Piwik\Plugins\UsersManager\API; use Piwik\Session; |