From ca8971ef9e8cd22bf22d6e805c315a37f2f49b9c Mon Sep 17 00:00:00 2001 From: Matthieu Aubry <mattab@users.noreply.github.com> Date: Mon, 24 Jul 2017 15:06:24 +1200 Subject: [PATCH] Allow logging in Debug level the SQL queries of all log archivers (#11812) * Debug log archiver queries * comment out --- core/DataAccess/LogAggregator.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/core/DataAccess/LogAggregator.php b/core/DataAccess/LogAggregator.php index 4651394556..522a46fe95 100644 --- a/core/DataAccess/LogAggregator.php +++ b/core/DataAccess/LogAggregator.php @@ -10,10 +10,12 @@ namespace Piwik\DataAccess; use Piwik\ArchiveProcessor\Parameters; use Piwik\Common; +use Piwik\Container\StaticContainer; use Piwik\DataArray; use Piwik\Db; use Piwik\Metrics; use Piwik\Tracker\GoalManager; +use Psr\Log\LoggerInterface; /** * Contains methods that calculate metrics by aggregating log data (visits, actions, conversions, @@ -140,17 +142,24 @@ class LogAggregator */ private $queryOriginHint = ''; + /** + * @var LoggerInterface + */ + private $logger; + + /** * Constructor. * * @param \Piwik\ArchiveProcessor\Parameters $params */ - public function __construct(Parameters $params) + public function __construct(Parameters $params, LoggerInterface $logger = null) { $this->dateStart = $params->getDateStart(); $this->dateEnd = $params->getDateEnd(); $this->segment = $params->getSegment(); $this->sites = $params->getIdSites(); + $this->logger = $logger ?: StaticContainer::get('Psr\Log\LoggerInterface'); } public function setQueryOriginHint($nameOfOrigiin) @@ -169,6 +178,9 @@ class LogAggregator $query['sql'] = 'SELECT /* ' . $this->queryOriginHint . ' */' . substr($query['sql'], strlen($select)); } + // Uncomment to log on DEBUG level all archiving queries + // $this->logger->debug($query['sql']); + return $query; } -- GitLab