diff options
author | Thomas Steur <thomas.steur@googlemail.com> | 2014-03-25 02:06:02 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-03-25 02:06:02 +0400 |
commit | dbe8a799d7e7fc8417b13ac8838f963d6187a5dc (patch) | |
tree | 211a000d9af9ddff863a851a1e89fcbe74d32187 | |
parent | 0ab1d1040899ddf03ba5386a78523e7d2c780442 (diff) |
refs #4780 added possibility to enable tracker debug via config, use logger for printing debug messages which allows users to log to screen, file or db
-rw-r--r-- | config/global.ini.php | 4 | ||||
-rw-r--r-- | core/Common.php | 13 | ||||
-rw-r--r-- | core/Log.php | 7 | ||||
-rw-r--r-- | core/Tracker.php | 7 | ||||
-rw-r--r-- | piwik.php | 8 |
5 files changed, 27 insertions, 12 deletions
diff --git a/config/global.ini.php b/config/global.ini.php index 94d45e6f94..553d6a9c14 100644 --- a/config/global.ini.php +++ b/config/global.ini.php @@ -400,6 +400,10 @@ enable_update_communication = 1 ; this is useful when you want to do cross websites analysis use_third_party_id_cookie = 0 +; If tracking does not work for you or you are stuck finding an issue, you might want to enable the tracker debug mode. +; Once enabled (set to 1) messages will be logged to all loggers defined in "[log] log_writers" config. +debug = 0 + ; There is a feature in the Tracking API that lets you create new visit at any given time, for example if you know that a different user/customer is using ; the app then you would want to tell Piwik to create a new visit (even though both users are using the same browser/computer). ; To prevent abuse and easy creation of fake visits, this feature requires admin token_auth by default diff --git a/core/Common.php b/core/Common.php index b25047f078..ec31f88280 100644 --- a/core/Common.php +++ b/core/Common.php @@ -31,7 +31,6 @@ class Common public static $isCliMode = null; - /* * Database */ @@ -1062,17 +1061,19 @@ class Common static public function printDebug($info = '') { if (isset($GLOBALS['PIWIK_TRACKER_DEBUG']) && $GLOBALS['PIWIK_TRACKER_DEBUG']) { - if(is_object($info)) { + + if (is_object($info)) { $info = var_export($info, true); } + + Log::getInstance()->setLogLevel(Log::DEBUG); + if (is_array($info)) { - print("<pre>"); $info = Common::sanitizeInputValues($info); $out = var_export($info, true); - echo $out; - print("</pre>"); + Log::debug($out); } else { - print(htmlspecialchars($info, ENT_QUOTES) . "<br />\n"); + Log::debug(htmlspecialchars($info, ENT_QUOTES)); } } } diff --git a/core/Log.php b/core/Log.php index b6f8230735..76e59709df 100644 --- a/core/Log.php +++ b/core/Log.php @@ -290,7 +290,7 @@ class Log extends Singleton if ($logLevel >= self::NONE // sanity check && $logLevel <= self::VERBOSE ) { - $this->currentLogLevel = $logLevel; + $this->setLogLevel($logLevel); } } } @@ -355,6 +355,11 @@ class Log extends Singleton return $writers; } + public function setLogLevel($logLevel) + { + $this->currentLogLevel = $logLevel; + } + private function logToFile($level, $tag, $datetime, $message) { if (is_string($message)) { diff --git a/core/Tracker.php b/core/Tracker.php index 463b3a3a9a..c67d2e91f1 100644 --- a/core/Tracker.php +++ b/core/Tracker.php @@ -350,7 +350,10 @@ class Tracker // restore original user privilege Piwik::setUserHasSuperUserAccess($isSuperUser); - Common::printDebug($resultTasks); + foreach (explode('</pre>', $resultTasks) as $resultTask) { + Common::printDebug(str_replace('<pre>', '', $resultTask)); + } + Common::printDebug('Finished Scheduled Tasks.'); } else { Common::printDebug("-> Scheduled tasks not triggered."); @@ -851,7 +854,7 @@ class Tracker Common::printDebug("The request is invalid: empty request, or maybe tracking is disabled in the config.ini.php via record_statistics=0"); } } catch (DbException $e) { - Common::printDebug("<b>" . $e->getMessage() . "</b>"); + Common::printDebug("Exception: " . $e->getMessage()); $this->exitWithException($e, $isAuthenticated); } catch (Exception $e) { $this->exitWithException($e, $isAuthenticated); @@ -12,7 +12,6 @@ use Piwik\Common; use Piwik\Timer; use Piwik\Tracker; -$GLOBALS['PIWIK_TRACKER_DEBUG'] = false; $GLOBALS['PIWIK_TRACKER_DEBUG_FORCE_SCHEDULED_TASKS'] = false; define('PIWIK_ENABLE_TRACKING', true); @@ -84,6 +83,9 @@ if (!defined('PIWIK_ENABLE_TRACKING') || PIWIK_ENABLE_TRACKING) { ob_start(); } +\Piwik\FrontController::createConfigObject(); + +$GLOBALS['PIWIK_TRACKER_DEBUG'] = \Piwik\Config::getInstance()->Tracker['debug']; if ($GLOBALS['PIWIK_TRACKER_DEBUG'] === true) { require_once PIWIK_INCLUDE_PATH . '/core/Loader.php'; @@ -93,10 +95,10 @@ if ($GLOBALS['PIWIK_TRACKER_DEBUG'] === true) { \Piwik\ExceptionHandler::setUp(); $timer = new Timer(); - Common::printDebug("Debug enabled - Input parameters: <br/>" . var_export($_GET, true)); + Common::printDebug("Debug enabled - Input parameters: "); + Common::printDebug(var_export($_GET, true)); \Piwik\Tracker\Db::enableProfiling(); - \Piwik\FrontController::createConfigObject(); } if (!defined('PIWIK_ENABLE_TRACKING') || PIWIK_ENABLE_TRACKING) { |