diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/API/Proxy.php | 12 | ||||
-rw-r--r-- | core/API/Request.php | 7 | ||||
-rw-r--r-- | core/API/ResponseBuilder.php | 15 | ||||
-rw-r--r-- | core/ArchiveProcessor/PluginsArchiver.php | 2 | ||||
-rw-r--r-- | core/CliMulti.php | 5 | ||||
-rw-r--r-- | core/Development.php | 9 | ||||
-rw-r--r-- | core/ErrorHandler.php | 4 | ||||
-rw-r--r-- | core/ExceptionHandler.php | 21 | ||||
-rw-r--r-- | core/FrontController.php | 11 | ||||
-rw-r--r-- | core/Plugin/ViewDataTable.php | 2 | ||||
-rw-r--r-- | core/Plugin/Visualization.php | 11 | ||||
-rw-r--r-- | core/Session.php | 6 | ||||
-rw-r--r-- | core/testMinimumPhpVersion.php | 6 |
13 files changed, 80 insertions, 31 deletions
diff --git a/core/API/Proxy.php b/core/API/Proxy.php index 34b202f94d..1f2ca5a59d 100644 --- a/core/API/Proxy.php +++ b/core/API/Proxy.php @@ -11,6 +11,7 @@ namespace Piwik\API; use Exception; use Piwik\Common; +use Piwik\Container\StaticContainer; use Piwik\Context; use Piwik\Piwik; use Piwik\Plugin\Manager; @@ -25,15 +26,13 @@ use ReflectionMethod; * object, with the parameters in the right order. * * It will also log the performance of API calls (time spent, parameter values, etc.) if logger available - * - * @method static Proxy getInstance() */ -class Proxy extends Singleton +class Proxy { // array of already registered plugins names protected $alreadyRegistered = array(); - private $metadataArray = array(); + protected $metadataArray = array(); private $hideIgnoredFunctions = true; // when a parameter doesn't have a default value we use this @@ -44,6 +43,11 @@ class Proxy extends Singleton $this->noDefaultValue = new NoDefaultValue(); } + public static function getInstance() + { + return StaticContainer::get(self::class); + } + /** * Returns array containing reflection meta data for all the loaded classes * eg. number of parameters, method names, etc. diff --git a/core/API/Request.php b/core/API/Request.php index 5356a94e6e..1875e2822a 100644 --- a/core/API/Request.php +++ b/core/API/Request.php @@ -12,6 +12,7 @@ use Exception; use Piwik\Access; use Piwik\Cache; use Piwik\Common; +use Piwik\Container\StaticContainer; use Piwik\Context; use Piwik\DataTable; use Piwik\Exception\PluginDeactivatedException; @@ -23,6 +24,7 @@ use Piwik\Plugins\CoreHome\LoginWhitelist; use Piwik\SettingsServer; use Piwik\Url; use Piwik\UrlHelper; +use Psr\Log\LoggerInterface; /** * Dispatches API requests to the appropriate API method. @@ -269,7 +271,10 @@ class Request return $response->getResponse($returnedValue, $module, $method); }); } catch (Exception $e) { - Log::debug($e); + StaticContainer::get(LoggerInterface::class)->error('Uncaught exception in API: {exception}', [ + 'exception' => $e, + 'ignoreInScreenWriter' => true, + ]); $toReturn = $response->getResponseException($e); } finally { diff --git a/core/API/ResponseBuilder.php b/core/API/ResponseBuilder.php index a3730d3fe0..9845dee275 100644 --- a/core/API/ResponseBuilder.php +++ b/core/API/ResponseBuilder.php @@ -15,6 +15,7 @@ use Piwik\DataTable\Renderer; use Piwik\DataTable\DataTableInterface; use Piwik\DataTable\Filter\ColumnDelete; use Piwik\DataTable\Filter\Pattern; +use Piwik\Plugins\Monolog\Processor\ExceptionToTextProcessor; /** */ @@ -165,19 +166,7 @@ class ResponseBuilder */ private function formatExceptionMessage($exception) { - $message = ""; - - $e = $exception; - do { - if ($e !== $exception) { - $message .= ",\ncaused by: "; - } - - $message .= $e->getMessage(); - if ($this->shouldPrintBacktrace) { - $message .= "\n" . $e->getTraceAsString(); - } - } while ($e = $e->getPrevious()); + $message = ExceptionToTextProcessor::getWholeBacktrace($exception, $this->shouldPrintBacktrace); return Renderer::formatValueXml($message); } diff --git a/core/ArchiveProcessor/PluginsArchiver.php b/core/ArchiveProcessor/PluginsArchiver.php index 11adfe7f1d..2f7cd1ad12 100644 --- a/core/ArchiveProcessor/PluginsArchiver.php +++ b/core/ArchiveProcessor/PluginsArchiver.php @@ -10,13 +10,11 @@ namespace Piwik\ArchiveProcessor; use Piwik\ArchiveProcessor; -use Piwik\Common; use Piwik\Container\StaticContainer; use Piwik\CronArchive\Performance\Logger; use Piwik\DataAccess\ArchiveWriter; use Piwik\DataAccess\LogAggregator; use Piwik\DataTable\Manager; -use Piwik\ErrorHandler; use Piwik\Metrics; use Piwik\Piwik; use Piwik\Plugin\Archiver; diff --git a/core/CliMulti.php b/core/CliMulti.php index d8d533ea24..b459bd69b6 100644 --- a/core/CliMulti.php +++ b/core/CliMulti.php @@ -447,4 +447,9 @@ class CliMulti $minutes = floor($elapsed / 60); return self::BASE_WAIT_TIME + $minutes * 100000; // 100 * 1000 = 100ms } + + public static function isCliMultiRequest() + { + return Common::getRequestVar('pid', false) !== false; + } } diff --git a/core/Development.php b/core/Development.php index 3b44eba71d..4660f83d9e 100644 --- a/core/Development.php +++ b/core/Development.php @@ -10,6 +10,8 @@ namespace Piwik; use Exception; +use Piwik\Container\StaticContainer; +use Psr\Log\LoggerInterface; /** * Development related checks and tools. You can enable/disable development using `./console development:enable` and @@ -150,8 +152,11 @@ class Development $message .= ' (This error is only shown in development mode)'; if (SettingsServer::isTrackerApiRequest() - || Common::isPhpCliMode()) { - Log::error($message); + || Common::isPhpCliMode() + ) { + StaticContainer::get(LoggerInterface::class)->error($message, [ + 'ignoreInScreenWriter' => true, + ]); } else { throw new Exception($message); } diff --git a/core/ErrorHandler.php b/core/ErrorHandler.php index e0a677cc53..b017d5e333 100644 --- a/core/ErrorHandler.php +++ b/core/ErrorHandler.php @@ -8,7 +8,9 @@ namespace Piwik; +use Piwik\Container\StaticContainer; use Piwik\Exception\ErrorException; +use Psr\Log\LoggerInterface; /** * Piwik's error handler function. @@ -160,7 +162,7 @@ class ErrorHandler case E_USER_DEPRECATED: default: try { - Log::warning(self::createLogMessage($errno, $errstr, $errfile, $errline)); + StaticContainer::get(LoggerInterface::class)->warning(self::createLogMessage($errno, $errstr, $errfile, $errline)); } catch (\Exception $ex) { // ignore (it's possible for this to happen if the StaticContainer hasn't been created yet) } diff --git a/core/ExceptionHandler.php b/core/ExceptionHandler.php index 6c01785b95..c1f959ce6d 100644 --- a/core/ExceptionHandler.php +++ b/core/ExceptionHandler.php @@ -9,10 +9,13 @@ namespace Piwik; use Exception; +use Interop\Container\Exception\ContainerException; use Piwik\API\Request; use Piwik\API\ResponseBuilder; use Piwik\Container\ContainerDoesNotExistException; +use Piwik\Container\StaticContainer; use Piwik\Plugins\CoreAdminHome\CustomLogo; +use Psr\Log\LoggerInterface; /** * Contains Piwik's uncaught exception handler. @@ -41,6 +44,8 @@ class ExceptionHandler */ public static function dieWithCliError($exception) { + self::logException($exception); + $message = $exception->getMessage(); if (!method_exists($exception, 'isHtmlMessage') || !$exception->isHtmlMessage()) { @@ -65,6 +70,8 @@ class ExceptionHandler */ public static function dieWithHtmlErrorPage($exception) { + self::logException($exception); + Common::sendHeader('Content-Type: text/html; charset=utf-8'); try { @@ -137,4 +144,18 @@ class ExceptionHandler return $result; } + + private static function logException($exception) + { + try { + StaticContainer::get(LoggerInterface::class)->error('Uncaught exception: {exception}', [ + 'exception' => $exception, + 'ignoreInScreenWriter' => true, + ]); + } catch (ContainerException $ex) { + // ignore (occurs if exception is thrown when resolving DI entries) + } catch (ContainerDoesNotExistException $ex) { + // ignore + } + } } diff --git a/core/FrontController.php b/core/FrontController.php index 8a32c425b0..320239f45b 100644 --- a/core/FrontController.php +++ b/core/FrontController.php @@ -21,6 +21,7 @@ use Piwik\Http\ControllerResolver; use Piwik\Http\Router; use Piwik\Plugins\CoreAdminHome\CustomLogo; use Piwik\Session\SessionAuth; +use Psr\Log\LoggerInterface; /** * This singleton dispatches requests to the appropriate plugin Controller. @@ -107,6 +108,11 @@ class FrontController extends Singleton */ private static function generateSafeModeOutputFromException($e) { + StaticContainer::get(LoggerInterface::class)->error('Uncaught exception: {exception}', [ + 'exception' => $e, + 'ignoreInScreenWriter' => true, + ]); + $error = array( 'message' => $e->getMessage(), 'file' => $e->getFile(), @@ -256,6 +262,11 @@ class FrontController extends Singleton $lastError['backtrace'] = ' on ' . $lastError['file'] . '(' . $lastError['line'] . ")\n" . ErrorHandler::getFatalErrorPartialBacktrace(); + StaticContainer::get(LoggerInterface::class)->error('Fatal error encountered: {exception}', [ + 'exception' => $lastError, + 'ignoreInScreenWriter' => true, + ]); + $message = self::generateSafeModeOutputFromError($lastError); echo $message; } diff --git a/core/Plugin/ViewDataTable.php b/core/Plugin/ViewDataTable.php index 226e8f3141..513d175d1f 100644 --- a/core/Plugin/ViewDataTable.php +++ b/core/Plugin/ViewDataTable.php @@ -13,8 +13,6 @@ use Piwik\Common; use Piwik\DataTable; use Piwik\Period; use Piwik\Piwik; -use Piwik\Plugin\ReportsProvider; -use Piwik\View; use Piwik\View\ViewInterface; use Piwik\ViewDataTable\Config as VizConfig; use Piwik\ViewDataTable\Manager as ViewDataTableManager; diff --git a/core/Plugin/Visualization.php b/core/Plugin/Visualization.php index 71c9eca248..f23a183ed6 100644 --- a/core/Plugin/Visualization.php +++ b/core/Plugin/Visualization.php @@ -28,6 +28,7 @@ use Piwik\View; use Piwik\ViewDataTable\Manager as ViewDataTableManager; use Piwik\Plugin\Manager as PluginManager; use Piwik\API\Request as ApiRequest; +use Psr\Log\LoggerInterface; /** * The base class for report visualizations that output HTML and use JavaScript. @@ -193,16 +194,16 @@ class Visualization extends ViewDataTable } catch (NoAccessException $e) { throw $e; } catch (\Exception $e) { - $logMessage = "Failed to get data from API: " . $e->getMessage(); - $message = $e->getMessage(); + StaticContainer::get(LoggerInterface::class)->error('Failed to get data from API: {exception}', [ + 'exception' => $e, + 'ignoreInScreenWriter' => true, + ]); + $message = $e->getMessage(); if (\Piwik_ShouldPrintBackTraceWithMessage()) { - $logMessage .= "\n" . $e->getTraceAsString(); $message .= "\n" . $e->getTraceAsString(); } - Log::error($logMessage); - $loadingError = array('message' => $message); } diff --git a/core/Session.php b/core/Session.php index b03c8e0796..bf523d3b71 100644 --- a/core/Session.php +++ b/core/Session.php @@ -12,6 +12,7 @@ use Exception; use Piwik\Container\StaticContainer; use Piwik\Exception\MissingFilePermissionException; use Piwik\Session\SaveHandler\DbTable; +use Psr\Log\LoggerInterface; use Zend_Session; /** @@ -132,7 +133,10 @@ class Session extends Zend_Session parent::start(); register_shutdown_function(array('Zend_Session', 'writeClose'), true); } catch (Exception $e) { - Log::error('Unable to start session: ' . $e->getMessage()); + StaticContainer::get(LoggerInterface::class)->error('Unable to start session: {exception}', [ + 'exception' => $e, + 'ignoreInScreenWriter' => true, + ]); if (SettingsPiwik::isPiwikInstalled()) { $pathToSessions = ''; diff --git a/core/testMinimumPhpVersion.php b/core/testMinimumPhpVersion.php index 82bbc4fd88..c1f8338081 100644 --- a/core/testMinimumPhpVersion.php +++ b/core/testMinimumPhpVersion.php @@ -84,6 +84,12 @@ if (!function_exists('Piwik_GetErrorMessagePage')) { */ function Piwik_ShouldPrintBackTraceWithMessage() { + if (\Piwik\SettingsServer::isArchivePhpTriggered() + && \Piwik\Common::isPhpCliMode() + ) { + return true; + } + $bool = (defined('PIWIK_PRINT_ERROR_BACKTRACE') && PIWIK_PRINT_ERROR_BACKTRACE) || !empty($GLOBALS['PIWIK_TRACKER_DEBUG']); |