Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenaka Moorthi <benaka.moorthi@gmail.com>2013-09-24 08:47:46 +0400
committerBenaka Moorthi <benaka.moorthi@gmail.com>2013-09-24 08:47:46 +0400
commit13f27b3b03abb2ffd06b8eeefcb79b8af98f1e9c (patch)
tree285a3bdae3f87f4d818ccff3d999588e9cd19495
parent2cb3bca565e0251fa7ecd74246d05f4cbdc1aa61 (diff)
Fixing ErrorHandler stuff.
-rw-r--r--config/global.ini.php4
-rw-r--r--core/Error.php137
-rw-r--r--core/ErrorHandler.php79
-rw-r--r--core/Profiler.php3
-rw-r--r--index.php6
5 files changed, 143 insertions, 86 deletions
diff --git a/config/global.ini.php b/config/global.ini.php
index 3b4ed4ba05..ea88315cde 100644
--- a/config/global.ini.php
+++ b/config/global.ini.php
@@ -494,10 +494,6 @@ log_only_when_debug_parameter = 0
; eg. if the value is tmp/logs files will be created in /path/to/piwik/tmp/logs/
logger_file_path = tmp/logs
-; all calls to the API (method name, parameters, execution time, caller IP, etc.)
-; disabled by default as it can cause serious overhead and should only be used wisely
-;logger_api_call[] = file
-
[Plugins]
Plugins[] = CorePluginsAdmin
Plugins[] = CoreAdminHome
diff --git a/core/Error.php b/core/Error.php
new file mode 100644
index 0000000000..fc5adc919e
--- /dev/null
+++ b/core/Error.php
@@ -0,0 +1,137 @@
+<?php
+/**
+ * Piwik - Open source web analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ * @category Piwik
+ * @package Piwik
+ */
+namespace Piwik;
+
+use Piwik\Log;
+
+/**
+ * TODO
+ */
+class Error
+{
+ /**
+ * TODO
+ */
+ private $errno;
+
+ /**
+ * TODO
+ */
+ private $errstr;
+
+ /**
+ * TODO
+ */
+ private $errfile;
+
+ /**
+ * TODO
+ */
+ private $errline;
+
+ /**
+ * TODO
+ */
+ private $backtrace;
+
+ /**
+ * TODO
+ */
+ public function __construct($errno, $errstr, $errfile, $errline, $backtrace)
+ {
+ $this->errno = $errno;
+ $this->errstr = $errstr;
+ $this->errfile = $errfile;
+ $this->errline = $errline;
+ $this->backgrace = $backtrace;
+ }
+
+ public static function formatFileAndDBLogMessage(&$message, $level, $pluginName, $datetime)
+ {
+ if ($message instanceof Error) {
+ // TODO
+ }
+ }
+
+ public static function formatScreenMessage(&$message, $level, $pluginName, $datetime)
+ {
+ if ($message instanceof Error) {
+ // TODO
+ }
+ }
+
+ public static function setErrorHandler()
+ {
+ Piwik_AddAction('Log.formatFileMessage', array('Error', 'formatFileAndDBLogMessage'));
+ Piwik_AddAction('Log.formatDatabaseMessage', array('Error', 'formatFileAndDBLogMessage'));
+ Piwik_AddAction('Log.formatScreenMessage', array('Error', 'formatScreenMessage'));
+
+ set_error_handler(array('Error', 'errorHandler'));
+ }
+
+ public static function errorHandler($errno, $errstr, $errfile, $errline)
+ {
+ // if the error has been suppressed by the @ we don't handle the error
+ if (error_reporting() == 0) {
+ return;
+ }
+
+ $plugin = false;
+
+ $backtrace = '';
+ $bt = @debug_backtrace();
+ if ($bt !== null && isset($bt[0])) {
+ foreach ($bt as $i => $debug) {
+ $backtrace .= "#$i "
+ . (isset($debug['class']) ? $debug['class'] : '')
+ . (isset($debug['type']) ? $debug['type'] : '')
+ . (isset($debug['function']) ? $debug['function'] : '')
+ . '(...) called at ['
+ . (isset($debug['file']) ? $debug['file'] : '') . ':'
+ . (isset($debug['line']) ? $debug['line'] : '') . ']' . "\n";
+
+ // try and discern the plugin name
+ if (empty($plugin)) {
+ if (preg_match("/^Piwik\\Plugins\\([a-z_]+)\\/", $debug['class'], $matches)) {
+ $plugin = $matches[1];
+ }
+ }
+ }
+ }
+
+ $error = new Error($errno, $errstr, $errfile, $errline, $backtrace); // TODO (also logger_error formatting)
+ Log::e($plugin ?: 'unknown', $error);
+
+ switch ($errno) {
+ case E_ERROR:
+ case E_PARSE:
+ case E_CORE_ERROR:
+ case E_CORE_WARNING:
+ case E_COMPILE_ERROR:
+ case E_COMPILE_WARNING:
+ case E_USER_ERROR:
+ exit;
+ break;
+
+ case E_WARNING:
+ case E_NOTICE:
+ case E_USER_WARNING:
+ case E_USER_NOTICE:
+ case E_STRICT:
+ case E_RECOVERABLE_ERROR:
+ case E_DEPRECATED:
+ case E_USER_DEPRECATED:
+ default:
+ // do not exit
+ break;
+ }
+ }
+} \ No newline at end of file
diff --git a/core/ErrorHandler.php b/core/ErrorHandler.php
deleted file mode 100644
index 963d46e3f6..0000000000
--- a/core/ErrorHandler.php
+++ /dev/null
@@ -1,79 +0,0 @@
-<?php
-/**
- * Piwik - Open source web analytics
- *
- * @link http://piwik.org
- * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
- *
- * @category Piwik
- * @package Piwik
- */
-
-/**
- * Error handler used to display nicely errors in Piwik
- *
- * @param int $errno Error number
- * @param string $errstr Error message
- * @param string $errfile File name
- * @param int $errline Line number
- * @return void
- */
-function Piwik_ErrorHandler($errno, $errstr, $errfile, $errline)
-{
- // if the error has been suppressed by the @ we don't handle the error
- if (error_reporting() == 0) {
- return;
- }
-
- if (function_exists('debug_backtrace')) {
- $backtrace = '';
- $bt = @debug_backtrace();
- if ($bt !== null && isset($bt[0])) {
- foreach ($bt as $i => $debug) {
- $backtrace .= "#$i "
- . (isset($debug['class']) ? $debug['class'] : '')
- . (isset($debug['type']) ? $debug['type'] : '')
- . (isset($debug['function']) ? $debug['function'] : '')
- . '(...) called at ['
- . (isset($debug['file']) ? $debug['file'] : '') . ':'
- . (isset($debug['line']) ? $debug['line'] : '') . ']' . "\n";
- }
- }
- } else {
- ob_start();
- @debug_print_backtrace();
- $backtrace = ob_get_contents();
- ob_end_clean();
- }
-
- try {
- \Zend_Registry::get('logger_error')->logEvent($errno, $errstr, $errfile, $errline, $backtrace);
- } catch (Exception $e) {
- // in case the error occurs before the logger creation, we simply display it
- print("<pre>$errstr \nin '$errfile' at the line $errline\n\n$backtrace\n</pre>");
- exit;
- }
- switch ($errno) {
- case E_ERROR:
- case E_PARSE:
- case E_CORE_ERROR:
- case E_CORE_WARNING:
- case E_COMPILE_ERROR:
- case E_COMPILE_WARNING:
- case E_USER_ERROR:
- exit;
- break;
-
- case E_WARNING:
- case E_NOTICE:
- case E_USER_WARNING:
- case E_USER_NOTICE:
- case E_STRICT:
- case E_RECOVERABLE_ERROR:
- case E_DEPRECATED:
- case E_USER_DEPRECATED:
- default:
- // do not exit
- break;
- }
-}
diff --git a/core/Profiler.php b/core/Profiler.php
index b959e3990c..2422f5db25 100644
--- a/core/Profiler.php
+++ b/core/Profiler.php
@@ -17,7 +17,8 @@ namespace Piwik;
* enable_sql_profiler = 1
*
* [log]
- * logger_message[]="screen"
+ * log_writers[] = file
+ * log_level=debug
*
* @package Piwik
*/
diff --git a/index.php b/index.php
index 4347ddd41d..0839100d32 100644
--- a/index.php
+++ b/index.php
@@ -9,6 +9,7 @@
*/
use Piwik\FrontController;
+use Piwik\Error;
define('PIWIK_DOCUMENT_ROOT', dirname(__FILE__) == '/' ? '' : dirname(__FILE__));
if (file_exists(PIWIK_DOCUMENT_ROOT . '/bootstrap.php')) {
@@ -39,9 +40,10 @@ require_once PIWIK_INCLUDE_PATH . '/core/Loader.php';
require_once PIWIK_INCLUDE_PATH . '/core/functions.php';
if (!defined('PIWIK_ENABLE_ERROR_HANDLER') || PIWIK_ENABLE_ERROR_HANDLER) {
- require_once PIWIK_INCLUDE_PATH . '/core/ErrorHandler.php';
+ require_once PIWIK_INCLUDE_PATH . '/core/Error.php';
+ Error::setErrorHandler();
+
require_once PIWIK_INCLUDE_PATH . '/core/ExceptionHandler.php';
- set_error_handler('Piwik_ErrorHandler');
set_exception_handler('Piwik_ExceptionHandler');
}