Skip to content

Commit

Permalink
refs matomo-org#4780 added possibility to enable tracker debug via co…
Browse files Browse the repository at this point in the history
…nfig, use logger for printing debug messages which allows users to log to screen, file or db
  • Loading branch information
tsteur committed Mar 24, 2014
1 parent 0ab1d10 commit dbe8a79
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
4 changes: 4 additions & 0 deletions config/global.ini.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,10 @@
; 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
Expand Down
13 changes: 7 additions & 6 deletions core/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class Common

public static $isCliMode = null;


/*
* Database
*/
Expand Down Expand Up @@ -1062,17 +1061,19 @@ static public function destroy(&$var)
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));
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion core/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private function setCurrentLogLevelFromConfig($logConfig)
if ($logLevel >= self::NONE // sanity check
&& $logLevel <= self::VERBOSE
) {
$this->currentLogLevel = $logLevel;
$this->setLogLevel($logLevel);
}
}
}
Expand Down Expand Up @@ -355,6 +355,11 @@ private function getAvailableWriters()
return $writers;
}

public function setLogLevel($logLevel)
{
$this->currentLogLevel = $logLevel;
}

private function logToFile($level, $tag, $datetime, $message)
{
if (is_string($message)) {
Expand Down
7 changes: 5 additions & 2 deletions core/Tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,10 @@ protected static function runScheduledTasks()
// 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.");
Expand Down Expand Up @@ -851,7 +854,7 @@ protected function trackRequest($params, $tokenAuth)
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);
Expand Down
8 changes: 5 additions & 3 deletions piwik.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Piwik\Timer;
use Piwik\Tracker;

$GLOBALS['PIWIK_TRACKER_DEBUG'] = false;
$GLOBALS['PIWIK_TRACKER_DEBUG_FORCE_SCHEDULED_TASKS'] = false;
define('PIWIK_ENABLE_TRACKING', true);

Expand Down Expand Up @@ -84,6 +83,9 @@
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';

Expand All @@ -93,10 +95,10 @@
\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) {
Expand Down

0 comments on commit dbe8a79

Please sign in to comment.