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:
authorThomas Steur <thomas.steur@gmail.com>2015-08-19 11:12:43 +0300
committerThomas Steur <thomas.steur@gmail.com>2015-08-19 13:56:26 +0300
commit763d19b594ff4e1aec4785e0816f7d57114c3a82 (patch)
tree9e2a4251c827fabd5b818a50d1eb6bbe07cf2516 /plugins/Monolog
parentde5f4f219a8eb2b6d23129bb2bf767581b5c3320 (diff)
use monolog in tracker
Diffstat (limited to 'plugins/Monolog')
-rw-r--r--plugins/Monolog/Handler/EchoHandler.php24
-rw-r--r--plugins/Monolog/config/config.php17
-rw-r--r--plugins/Monolog/config/tracker.php16
-rw-r--r--plugins/Monolog/tests/Integration/Fixture/LoggerWrapper.php (renamed from plugins/Monolog/Test/Integration/Fixture/LoggerWrapper.php)2
-rw-r--r--plugins/Monolog/tests/Integration/LogTest.php (renamed from plugins/Monolog/Test/Integration/LogTest.php)4
-rw-r--r--plugins/Monolog/tests/System/TrackerLoggingTest.php107
-rw-r--r--plugins/Monolog/tests/Unit/Formatter/LineMessageFormatterTest.php (renamed from plugins/Monolog/Test/Unit/Formatter/LineMessageFormatterTest.php)2
-rw-r--r--plugins/Monolog/tests/Unit/Processor/ClassNameProcessorTest.php (renamed from plugins/Monolog/Test/Unit/Processor/ClassNameProcessorTest.php)2
-rw-r--r--plugins/Monolog/tests/Unit/Processor/ExceptionToTextProcessorTest.php (renamed from plugins/Monolog/Test/Unit/Processor/ExceptionToTextProcessorTest.php)2
-rw-r--r--plugins/Monolog/tests/Unit/Processor/RequestIdProcessorTest.php (renamed from plugins/Monolog/Test/Unit/Processor/RequestIdProcessorTest.php)2
-rw-r--r--plugins/Monolog/tests/Unit/Processor/SprintfProcessorTest.php (renamed from plugins/Monolog/Test/Unit/Processor/SprintfProcessorTest.php)2
-rw-r--r--plugins/Monolog/tests/Unit/Processor/TokenProcessorTest.php (renamed from plugins/Monolog/Test/Unit/Processor/TokenProcessorTest.php)2
12 files changed, 166 insertions, 16 deletions
diff --git a/plugins/Monolog/Handler/EchoHandler.php b/plugins/Monolog/Handler/EchoHandler.php
new file mode 100644
index 0000000000..0a432cb3d6
--- /dev/null
+++ b/plugins/Monolog/Handler/EchoHandler.php
@@ -0,0 +1,24 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+
+namespace Piwik\Plugins\Monolog\Handler;
+
+use Monolog\Handler\AbstractProcessingHandler;
+
+/**
+ * Simply echos all messages.
+ */
+class EchoHandler extends AbstractProcessingHandler
+{
+ protected function write(array $record)
+ {
+ $message = $record['level_name'] . ': ' . $record['message'];
+
+ echo $message . "\n";
+ }
+}
diff --git a/plugins/Monolog/config/config.php b/plugins/Monolog/config/config.php
index 22cf7debee..5a9b2baf5c 100644
--- a/plugins/Monolog/config/config.php
+++ b/plugins/Monolog/config/config.php
@@ -11,17 +11,24 @@ return array(
'Psr\Log\LoggerInterface' => DI\get('Monolog\Logger'),
+ 'log.handler.classes' => DI\factory(function (ContainerInterface $c) {
+ $classes = array(
+ 'file' => 'Piwik\Plugins\Monolog\Handler\FileHandler',
+ 'screen' => 'Piwik\Plugins\Monolog\Handler\WebNotificationHandler',
+ 'database' => 'Piwik\Plugins\Monolog\Handler\DatabaseHandler',
+ );
+
+ return $classes;
+ }),
'log.handlers' => DI\factory(function (ContainerInterface $c) {
if ($c->has('ini.log.log_writers')) {
$writerNames = $c->get('ini.log.log_writers');
} else {
return array();
}
- $classes = array(
- 'file' => 'Piwik\Plugins\Monolog\Handler\FileHandler',
- 'screen' => 'Piwik\Plugins\Monolog\Handler\WebNotificationHandler',
- 'database' => 'Piwik\Plugins\Monolog\Handler\DatabaseHandler',
- );
+
+ $classes = $c->get('log.handler.classes');
+
$writerNames = array_map('trim', $writerNames);
$writers = array();
foreach ($writerNames as $writerName) {
diff --git a/plugins/Monolog/config/tracker.php b/plugins/Monolog/config/tracker.php
index c1a19a6618..a1220a7682 100644
--- a/plugins/Monolog/config/tracker.php
+++ b/plugins/Monolog/config/tracker.php
@@ -6,11 +6,23 @@ return array(
'Psr\Log\LoggerInterface' => function (ContainerInterface $c) {
$trackerDebug = $c->get("ini.Tracker.debug");
- if ($trackerDebug == 1) {
+ if ($trackerDebug == 1 || $GLOBALS['PIWIK_TRACKER_DEBUG']) {
return $c->get('Monolog\Logger');
} else {
return new \Psr\Log\NullLogger();
}
- }
+ },
+
+ 'log.handler.classes' => DI\decorate(function ($previous) {
+ if (isset($previous['screen'])) {
+ $previous['screen'] = 'Piwik\Plugins\Monolog\Handler\EchoHandler';
+ }
+
+ return $previous;
+ }),
+
+ 'log.level' => DI\factory(function (ContainerInterface $c) {
+ return \Monolog\Logger::DEBUG;
+ })
);
diff --git a/plugins/Monolog/Test/Integration/Fixture/LoggerWrapper.php b/plugins/Monolog/tests/Integration/Fixture/LoggerWrapper.php
index 0d5ea11264..325fba6627 100644
--- a/plugins/Monolog/Test/Integration/Fixture/LoggerWrapper.php
+++ b/plugins/Monolog/tests/Integration/Fixture/LoggerWrapper.php
@@ -6,7 +6,7 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
-namespace Piwik\Plugins\Monolog\Test\Integration\Fixture;
+namespace Piwik\Plugins\Monolog\tests\Integration\Fixture;
use Piwik\Log;
diff --git a/plugins/Monolog/Test/Integration/LogTest.php b/plugins/Monolog/tests/Integration/LogTest.php
index f26da4983d..97dc5e818f 100644
--- a/plugins/Monolog/Test/Integration/LogTest.php
+++ b/plugins/Monolog/tests/Integration/LogTest.php
@@ -6,7 +6,7 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
-namespace Piwik\Plugins\Monolog\Test\Integration;
+namespace Piwik\Plugins\Monolog\tests\Integration;
use Exception;
use Piwik\Application\Environment;
@@ -15,7 +15,7 @@ use Piwik\Config;
use Piwik\Container\StaticContainer;
use Piwik\Db;
use Piwik\Log;
-use Piwik\Plugins\Monolog\Test\Integration\Fixture\LoggerWrapper;
+use Piwik\Plugins\Monolog\tests\Integration\Fixture\LoggerWrapper;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
/**
diff --git a/plugins/Monolog/tests/System/TrackerLoggingTest.php b/plugins/Monolog/tests/System/TrackerLoggingTest.php
new file mode 100644
index 0000000000..efbd7b838f
--- /dev/null
+++ b/plugins/Monolog/tests/System/TrackerLoggingTest.php
@@ -0,0 +1,107 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+
+namespace Piwik\Plugins\Monolog\tests\System;
+
+use Piwik\Config;
+use Piwik\Date;
+use Piwik\Tests\Framework\Fixture;
+use Piwik\Tests\Framework\TestCase\SystemTestCase;
+use PiwikTracker;
+
+/**
+ * @group Monolog
+ * @group TrackerLoggingTest
+ * @group Plugins
+ */
+class TrackerLoggingTest extends SystemTestCase
+{
+ private $idSite = 1;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $testingEnvironment = self::$fixture->getTestEnvironment();
+ $configOverride = $testingEnvironment->configOverride;
+ $configOverride['Tracker']['debug'] = 1;
+ $configOverride['log']['log_writers'] = array('screen');
+ $testingEnvironment->configOverride = $configOverride;
+ $testingEnvironment->save();
+
+ if (!Fixture::siteCreated($this->idSite)) {
+ Fixture::createWebsite('2014-01-01 00:00:00');
+ }
+ }
+
+ public function test_shouldReturnDebugOutput_IfDebugIsEnabled()
+ {
+ $this->setTrackerConfig(array('debug' => '1'));
+
+ $tracker = $this->buildTracker();
+ $this->assertTrackerResponseContainsLogOutput($tracker);
+ }
+
+ public function test_shouldReturnDebugOutput_IfDebugOnDemandIsEnabled()
+ {
+ $this->setTrackerConfig(array('debug_on_demand' => '1', 'debug' => 0));
+
+ $tracker = $this->buildTracker();
+ $tracker->setDebugStringAppend('debug=1');
+ $this->assertTrackerResponseContainsLogOutput($tracker);
+ }
+
+ public function test_shouldNotReturnDebugOutput_IfDebugOnDemandIsDisabled()
+ {
+ $this->setTrackerConfig(array('debug_on_demand' => '0', 'debug' => 0));
+
+ $tracker = $this->buildTracker();
+ $tracker->setDebugStringAppend('debug=1');
+
+ Fixture::checkResponse($tracker->doTrackPageView('incredible title!'));
+ }
+
+ private function buildTracker()
+ {
+ $t = Fixture::getTracker($this->idSite, Date::factory('2014-01-05 00:01:01')->getDatetime());
+ $t->setDebugStringAppend('debug=1');
+ $t->setTokenAuth(Fixture::getTokenAuth());
+ $t->setUrl('http://example.org/index1.htm');
+
+ return $t;
+ }
+
+ private function assertTrackerResponseContainsLogOutput(PiwikTracker $t)
+ {
+ $response = $t->doTrackPageView('incredible title!');
+
+ $this->assertStringStartsWith("DEBUG: Debug enabled - Input parameters:
+DEBUG: array (
+DEBUG: 'idsite' => '1',
+DEBUG: 'rec' => '1',
+DEBUG: 'apiv' => '1',", $response);
+ }
+
+ private function setTrackerConfig($trackerConfig)
+ {
+ $testingEnvironment = self::$fixture->getTestEnvironment();
+ $configOverride = $testingEnvironment->configOverride;
+ $configOverride['Tracker'] = $trackerConfig;
+ $configOverride['log']['log_writers'] = array('screen');
+ $testingEnvironment->configOverride = $configOverride;
+ $testingEnvironment->save();
+ }
+
+ public static function provideContainerConfigBeforeClass()
+ {
+ return array(
+ 'Psr\Log\LoggerInterface' => \DI\get('Monolog\Logger')
+ );
+ }
+
+} \ No newline at end of file
diff --git a/plugins/Monolog/Test/Unit/Formatter/LineMessageFormatterTest.php b/plugins/Monolog/tests/Unit/Formatter/LineMessageFormatterTest.php
index 2b53633e6d..eac798e9c7 100644
--- a/plugins/Monolog/Test/Unit/Formatter/LineMessageFormatterTest.php
+++ b/plugins/Monolog/tests/Unit/Formatter/LineMessageFormatterTest.php
@@ -6,7 +6,7 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
-namespace Piwik\Plugins\Monolog\Test\Unit\Formatter;
+namespace Piwik\Plugins\Monolog\tests\Unit\Formatter;
use DateTime;
use Piwik\Plugins\Monolog\Formatter\LineMessageFormatter;
diff --git a/plugins/Monolog/Test/Unit/Processor/ClassNameProcessorTest.php b/plugins/Monolog/tests/Unit/Processor/ClassNameProcessorTest.php
index b1b307a4d7..158aba272f 100644
--- a/plugins/Monolog/Test/Unit/Processor/ClassNameProcessorTest.php
+++ b/plugins/Monolog/tests/Unit/Processor/ClassNameProcessorTest.php
@@ -6,7 +6,7 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
-namespace Piwik\Plugins\Monolog\Test\Unit\Processor;
+namespace Piwik\Plugins\Monolog\tests\Unit\Processor;
use Piwik\Plugins\Monolog\Processor\ClassNameProcessor;
diff --git a/plugins/Monolog/Test/Unit/Processor/ExceptionToTextProcessorTest.php b/plugins/Monolog/tests/Unit/Processor/ExceptionToTextProcessorTest.php
index 5620325ef5..35c85ee17f 100644
--- a/plugins/Monolog/Test/Unit/Processor/ExceptionToTextProcessorTest.php
+++ b/plugins/Monolog/tests/Unit/Processor/ExceptionToTextProcessorTest.php
@@ -6,7 +6,7 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
-namespace Piwik\Plugins\Monolog\Test\Unit\Processor;
+namespace Piwik\Plugins\Monolog\tests\Unit\Processor;
use Piwik\Log;
use Piwik\Plugins\Monolog\Processor\ExceptionToTextProcessor;
diff --git a/plugins/Monolog/Test/Unit/Processor/RequestIdProcessorTest.php b/plugins/Monolog/tests/Unit/Processor/RequestIdProcessorTest.php
index 3fc3c6a2f9..8902103ed8 100644
--- a/plugins/Monolog/Test/Unit/Processor/RequestIdProcessorTest.php
+++ b/plugins/Monolog/tests/Unit/Processor/RequestIdProcessorTest.php
@@ -6,7 +6,7 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
-namespace Piwik\Plugins\Monolog\Test\Unit\Processor;
+namespace Piwik\Plugins\Monolog\tests\Unit\Processor;
use PHPUnit_Framework_TestCase;
use Piwik\Common;
diff --git a/plugins/Monolog/Test/Unit/Processor/SprintfProcessorTest.php b/plugins/Monolog/tests/Unit/Processor/SprintfProcessorTest.php
index 27ac6cbd02..53b6cb3910 100644
--- a/plugins/Monolog/Test/Unit/Processor/SprintfProcessorTest.php
+++ b/plugins/Monolog/tests/Unit/Processor/SprintfProcessorTest.php
@@ -6,7 +6,7 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
-namespace Piwik\Plugins\Monolog\Test\Unit\Processor;
+namespace Piwik\Plugins\Monolog\tests\Unit\Processor;
use Piwik\Plugins\Monolog\Processor\SprintfProcessor;
diff --git a/plugins/Monolog/Test/Unit/Processor/TokenProcessorTest.php b/plugins/Monolog/tests/Unit/Processor/TokenProcessorTest.php
index 574aaa64cb..c3fc419854 100644
--- a/plugins/Monolog/Test/Unit/Processor/TokenProcessorTest.php
+++ b/plugins/Monolog/tests/Unit/Processor/TokenProcessorTest.php
@@ -6,7 +6,7 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
-namespace Piwik\Plugins\Monolog\Test\Unit\Processor;
+namespace Piwik\Plugins\Monolog\tests\Unit\Processor;
use Piwik\Plugins\Monolog\Processor\TokenProcessor;