diff --git a/config/global.ini.php b/config/global.ini.php index 3a71c90683c0e665a20a00afc9ed215d7aedb1b1..5dba546c7bf6c42836b54681be84c4d652e1df46 100644 --- a/config/global.ini.php +++ b/config/global.ini.php @@ -732,6 +732,7 @@ Plugins[] = ExampleAPI Plugins[] = ExampleRssWidget Plugins[] = Provider Plugins[] = Feedback +Plugins[] = Monolog Plugins[] = Login Plugins[] = UsersManager diff --git a/config/global.php b/config/global.php index af8272d3de957eb9b5e74eeca5f146ef9b73c94e..aff73fcdba00409d733a1a115c5c5020e1f536b7 100644 --- a/config/global.php +++ b/config/global.php @@ -1,8 +1,6 @@ <?php use Interop\Container\ContainerInterface; -use Monolog\Logger; -use Piwik\Log; use Piwik\Cache\Eager; use Piwik\SettingsServer; @@ -52,87 +50,7 @@ return array( return 'eagercache-' . str_replace(array('.', '-'), '', \Piwik\Version::VERSION) . '-'; }, - // Log - 'Psr\Log\LoggerInterface' => DI\object('Monolog\Logger') - ->constructor('piwik', DI\link('log.handlers'), DI\link('log.processors')), - '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\Log\Handler\FileHandler', - 'screen' => 'Piwik\Log\Handler\WebNotificationHandler', - 'database' => 'Piwik\Log\Handler\DatabaseHandler', - ); - $writerNames = array_map('trim', $writerNames); - $writers = array(); - foreach ($writerNames as $writerName) { - if (isset($classes[$writerName])) { - $writers[$writerName] = $c->get($classes[$writerName]); - } - } - return array_values($writers); - }), - 'log.processors' => array( - DI\link('Piwik\Log\Processor\ClassNameProcessor'), - DI\link('Piwik\Log\Processor\RequestIdProcessor'), - DI\link('Piwik\Log\Processor\ExceptionToTextProcessor'), - DI\link('Piwik\Log\Processor\SprintfProcessor'), - DI\link('Monolog\Processor\PsrLogMessageProcessor'), - ), - 'Piwik\Log\Handler\FileHandler' => DI\object() - ->constructor(DI\link('log.file.filename'), DI\link('log.level')) - ->method('setFormatter', DI\link('Piwik\Log\Formatter\LineMessageFormatter')), - 'Piwik\Log\Handler\DatabaseHandler' => DI\object() - ->constructor(DI\link('log.level')) - ->method('setFormatter', DI\link('Piwik\Log\Formatter\LineMessageFormatter')), - 'Piwik\Log\Handler\WebNotificationHandler' => DI\object() - ->constructor(DI\link('log.level')) - ->method('setFormatter', DI\link('Piwik\Log\Formatter\LineMessageFormatter')), - 'log.level' => DI\factory(function (ContainerInterface $c) { - if ($c->has('ini.log.log_level')) { - $level = strtoupper($c->get('ini.log.log_level')); - if (!empty($level) && defined('Piwik\Log::'.strtoupper($level))) { - return Log::getMonologLevel(constant('Piwik\Log::'.strtoupper($level))); - } - } - return Logger::WARNING; - }), - 'log.file.filename' => DI\factory(function (ContainerInterface $c) { - $logPath = $c->get('ini.log.logger_file_path'); - - // Absolute path - if (strpos($logPath, '/') === 0) { - return $logPath; - } - - // Remove 'tmp/' at the beginning - if (strpos($logPath, 'tmp/') === 0) { - $logPath = substr($logPath, strlen('tmp')); - } - - if (empty($logPath)) { - // Default log file - $logPath = '/logs/piwik.log'; - } - - $logPath = $c->get('path.tmp') . $logPath; - if (is_dir($logPath)) { - $logPath .= '/piwik.log'; - } - - return $logPath; - }), - 'Piwik\Log\Formatter\LineMessageFormatter' => DI\object() - ->constructor(DI\link('log.format')), - 'log.format' => DI\factory(function (ContainerInterface $c) { - if ($c->has('ini.log.string_message_format')) { - return $c->get('ini.log.string_message_format'); - } - return '%level% %tag%[%datetime%] %message%'; - }), + 'Psr\Log\LoggerInterface' => DI\object('Psr\Log\NullLogger'), 'Piwik\Translation\Loader\LoaderInterface' => DI\object('Piwik\Translation\Loader\LoaderCache') ->constructor(DI\link('Piwik\Translation\Loader\JsonFileLoader')), diff --git a/core/Updates/2.11.0-b5.php b/core/Updates/2.11.0-b5.php new file mode 100644 index 0000000000000000000000000000000000000000..1a75fd9f88ab99b9d4f807deba3a75f8461e6675 --- /dev/null +++ b/core/Updates/2.11.0-b5.php @@ -0,0 +1,23 @@ +<?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\Updates; + +use Piwik\Plugin\Manager; +use Piwik\Updates; + +class Updates_2_11_0_b5 extends Updates +{ + static function update() + { + try { + Manager::getInstance()->activatePlugin('Monolog'); + } catch (\Exception $e) { + } + } +} diff --git a/core/Version.php b/core/Version.php index f67f64b6772261bedf6d82c4b9d9d9956f83fc97..644f25ec2109c298c1968394eeb21bf2de27990b 100644 --- a/core/Version.php +++ b/core/Version.php @@ -20,7 +20,7 @@ final class Version * The current Piwik version. * @var string */ - const VERSION = '2.11.0-b4'; + const VERSION = '2.11.0-b5'; public function isStableVersion($version) { diff --git a/misc/cron/archive.php b/misc/cron/archive.php index be81b9a6a7c94df645c31cd13bece277ab3603ad..eecd78946b37c69e9fbab098c0dfd8c8cb7f6d21 100644 --- a/misc/cron/archive.php +++ b/misc/cron/archive.php @@ -73,7 +73,7 @@ if (isset($_SERVER['argv']) && Piwik\Console::isSupported()) { /** @var \Monolog\Logger $logger */ $logger = StaticContainer::get('Psr\Log\LoggerInterface'); $handler = new StreamHandler('php://output', Logger::INFO); - $handler->setFormatter(StaticContainer::get('Piwik\Log\Formatter\LineMessageFormatter')); + $handler->setFormatter(StaticContainer::get('Piwik\Plugins\Monolog\Formatter\LineMessageFormatter')); $logger->pushHandler($handler); } diff --git a/core/Log/Formatter/LineMessageFormatter.php b/plugins/Monolog/Formatter/LineMessageFormatter.php similarity index 97% rename from core/Log/Formatter/LineMessageFormatter.php rename to plugins/Monolog/Formatter/LineMessageFormatter.php index 7c38fc32df0928337adf8aee1190515f62b7df37..6b81f2daeca16aa7623a38bab9b6aef67604a7d5 100644 --- a/core/Log/Formatter/LineMessageFormatter.php +++ b/plugins/Monolog/Formatter/LineMessageFormatter.php @@ -6,7 +6,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Log\Formatter; +namespace Piwik\Plugins\Monolog\Formatter; use Monolog\Formatter\FormatterInterface; diff --git a/core/Log/Handler/DatabaseHandler.php b/plugins/Monolog/Handler/DatabaseHandler.php similarity index 95% rename from core/Log/Handler/DatabaseHandler.php rename to plugins/Monolog/Handler/DatabaseHandler.php index 1cdcd0f8b9144bfe70fbbfe76998636fcb84739d..99ccd686704aa0e659a9ec420f174f0375db35c5 100644 --- a/core/Log/Handler/DatabaseHandler.php +++ b/plugins/Monolog/Handler/DatabaseHandler.php @@ -6,7 +6,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Log\Handler; +namespace Piwik\Plugins\Monolog\Handler; use Monolog\Handler\AbstractProcessingHandler; use Piwik\Common; diff --git a/core/Log/Handler/FileHandler.php b/plugins/Monolog/Handler/FileHandler.php similarity index 94% rename from core/Log/Handler/FileHandler.php rename to plugins/Monolog/Handler/FileHandler.php index 57f31610c1792735920caa34be2b4c4c421d8ffd..abfd6323650e45292227490a8eb13d1dc52122ac 100644 --- a/core/Log/Handler/FileHandler.php +++ b/plugins/Monolog/Handler/FileHandler.php @@ -6,7 +6,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Log\Handler; +namespace Piwik\Plugins\Monolog\Handler; use Monolog\Handler\StreamHandler; use Piwik\Filechecks; diff --git a/core/Log/Handler/WebNotificationHandler.php b/plugins/Monolog/Handler/WebNotificationHandler.php similarity index 97% rename from core/Log/Handler/WebNotificationHandler.php rename to plugins/Monolog/Handler/WebNotificationHandler.php index 37004d65218d7402d70ab320e5dc99854cc63f6c..edd2fc76c29706e50a8dd7210ac4603e6588996a 100644 --- a/core/Log/Handler/WebNotificationHandler.php +++ b/plugins/Monolog/Handler/WebNotificationHandler.php @@ -6,7 +6,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Log\Handler; +namespace Piwik\Plugins\Monolog\Handler; use Monolog\Handler\AbstractProcessingHandler; use Monolog\Logger; diff --git a/plugins/Monolog/Monolog.php b/plugins/Monolog/Monolog.php new file mode 100644 index 0000000000000000000000000000000000000000..79f42cdd41dfd263c2d07f9313cf9a01b49d6250 --- /dev/null +++ b/plugins/Monolog/Monolog.php @@ -0,0 +1,15 @@ +<?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; + +use Piwik\Plugin; + +class Monolog extends Plugin +{ +} diff --git a/core/Log/Processor/ClassNameProcessor.php b/plugins/Monolog/Processor/ClassNameProcessor.php similarity index 70% rename from core/Log/Processor/ClassNameProcessor.php rename to plugins/Monolog/Processor/ClassNameProcessor.php index a5b211d7d316bb4a012cfaf8c45c221f437bbbb6..3365f207db863d4a680ecbf2669ea79b3342c936 100644 --- a/core/Log/Processor/ClassNameProcessor.php +++ b/plugins/Monolog/Processor/ClassNameProcessor.php @@ -6,7 +6,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Log\Processor; +namespace Piwik\Plugins\Monolog\Processor; use Piwik\Plugin; @@ -52,7 +52,7 @@ class ClassNameProcessor private function getClassNameThatIsLogging($backtrace) { foreach ($backtrace as $line) { - if (isset($line['class']) && !in_array($line['class'], $this->skippedClasses)) { + if (isset($line['class'])) { return $line['class']; } } @@ -63,9 +63,19 @@ class ClassNameProcessor private function getBacktrace() { if (version_compare(phpversion(), '5.3.6', '>=')) { - return debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); + } else { + $backtrace = debug_backtrace(); } - return debug_backtrace(); + $skippedClasses = $this->skippedClasses; + $backtrace = array_filter($backtrace, function ($item) use ($skippedClasses) { + if (isset($item['class'])) { + return !in_array($item['class'], $skippedClasses); + } + return true; + }); + + return $backtrace; } } diff --git a/core/Log/Processor/ExceptionToTextProcessor.php b/plugins/Monolog/Processor/ExceptionToTextProcessor.php similarity index 97% rename from core/Log/Processor/ExceptionToTextProcessor.php rename to plugins/Monolog/Processor/ExceptionToTextProcessor.php index c3d51ae9e59b5d7f7f2cf1049ae944bc712e57bd..daaaee479e63e0afb932155a4bd0ba827c8e21bd 100644 --- a/core/Log/Processor/ExceptionToTextProcessor.php +++ b/plugins/Monolog/Processor/ExceptionToTextProcessor.php @@ -6,7 +6,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Log\Processor; +namespace Piwik\Plugins\Monolog\Processor; use Piwik\ErrorHandler; use Piwik\Log; diff --git a/core/Log/Processor/RequestIdProcessor.php b/plugins/Monolog/Processor/RequestIdProcessor.php similarity index 94% rename from core/Log/Processor/RequestIdProcessor.php rename to plugins/Monolog/Processor/RequestIdProcessor.php index 46ae17372e3d98b308a2d14508c682d178695a1e..f36568193a23d915f9f7221d0a3dd18ba8d8e0e6 100644 --- a/core/Log/Processor/RequestIdProcessor.php +++ b/plugins/Monolog/Processor/RequestIdProcessor.php @@ -6,7 +6,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Log\Processor; +namespace Piwik\Plugins\Monolog\Processor; use Piwik\Common; diff --git a/core/Log/Processor/SprintfProcessor.php b/plugins/Monolog/Processor/SprintfProcessor.php similarity index 95% rename from core/Log/Processor/SprintfProcessor.php rename to plugins/Monolog/Processor/SprintfProcessor.php index 9032f5ba7af4f4227cff2428cda69d83417dbb10..dafa46e5ba6a46136304d8c8e2ece2e18072bd17 100644 --- a/core/Log/Processor/SprintfProcessor.php +++ b/plugins/Monolog/Processor/SprintfProcessor.php @@ -6,7 +6,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Log\Processor; +namespace Piwik\Plugins\Monolog\Processor; /** * Processes a log message using `sprintf()`. diff --git a/tests/PHPUnit/Integration/Log/Fixture/LoggerWrapper.php b/plugins/Monolog/Test/Integration/Fixture/LoggerWrapper.php similarity index 82% rename from tests/PHPUnit/Integration/Log/Fixture/LoggerWrapper.php rename to plugins/Monolog/Test/Integration/Fixture/LoggerWrapper.php index 07b8a04d20b4fb9d2a16892b7d4e67028eb73b97..0d5ea1126465102d8187a7100e3c5acc5b9f2bfd 100644 --- a/tests/PHPUnit/Integration/Log/Fixture/LoggerWrapper.php +++ b/plugins/Monolog/Test/Integration/Fixture/LoggerWrapper.php @@ -6,7 +6,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Integration\Log\Fixture; +namespace Piwik\Plugins\Monolog\Test\Integration\Fixture; use Piwik\Log; diff --git a/tests/PHPUnit/Integration/Log/LogTest.php b/plugins/Monolog/Test/Integration/LogTest.php similarity index 90% rename from tests/PHPUnit/Integration/Log/LogTest.php rename to plugins/Monolog/Test/Integration/LogTest.php index 0b6516185eea1977f59705f49406aebdd0cd215c..c21a2f82f502ca682df19bb3f3527aec9394dc0d 100644 --- a/tests/PHPUnit/Integration/Log/LogTest.php +++ b/plugins/Monolog/Test/Integration/LogTest.php @@ -6,7 +6,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Integration\Log; +namespace Piwik\Plugins\Monolog\Test\Integration; use Exception; use Piwik\Common; @@ -15,8 +15,8 @@ use Piwik\Container\ContainerFactory; use Piwik\Container\StaticContainer; use Piwik\Db; use Piwik\Log; +use Piwik\Plugins\Monolog\Test\Integration\Fixture\LoggerWrapper; use Piwik\Tests\Framework\TestCase\IntegrationTestCase; -use Piwik\Tests\Integration\Log\Fixture\LoggerWrapper; /** * @group Core @@ -28,10 +28,10 @@ class LogTest extends IntegrationTestCase const STRING_MESSAGE_FORMAT = '[%tag%] %message%'; const STRING_MESSAGE_FORMAT_SPRINTF = "[%s] %s"; - public static $expectedExceptionOutput = '[Piwik\Tests\Integration\Log\LogTest] LogTest.php(120): dummy error message + public static $expectedExceptionOutput = '[Monolog] LogTest.php(120): dummy error message dummy backtrace'; - public static $expectedErrorOutput = '[Piwik\Tests\Integration\Log\LogTest] dummyerrorfile.php(145): Unknown error (102) - dummy error string + public static $expectedErrorOutput = '[Monolog] dummyerrorfile.php(145): Unknown error (102) - dummy error string dummy backtrace'; public function setUp() @@ -82,7 +82,7 @@ class LogTest extends IntegrationTestCase Log::warning(self::TESTMESSAGE); - $this->checkBackend($backend, self::TESTMESSAGE, $formatMessage = true, $tag = __CLASS__); + $this->checkBackend($backend, self::TESTMESSAGE, $formatMessage = true, $tag = 'Monolog'); } /** @@ -94,7 +94,7 @@ class LogTest extends IntegrationTestCase Log::warning(self::TESTMESSAGE, " subst "); - $this->checkBackend($backend, sprintf(self::TESTMESSAGE, " subst "), $formatMessage = true, $tag = __CLASS__); + $this->checkBackend($backend, sprintf(self::TESTMESSAGE, " subst "), $formatMessage = true, $tag = 'Monolog'); } /** @@ -107,7 +107,7 @@ class LogTest extends IntegrationTestCase $error = new \ErrorException("dummy error string", 0, 102, "dummyerrorfile.php", 145); Log::error($error); - $this->checkBackend($backend, self::$expectedErrorOutput, $formatMessage = false, $tag = __CLASS__); + $this->checkBackend($backend, self::$expectedErrorOutput, $formatMessage = false, $tag = 'Monolog'); } /** @@ -120,7 +120,7 @@ class LogTest extends IntegrationTestCase $exception = new Exception("dummy error message"); Log::error($exception); - $this->checkBackend($backend, self::$expectedExceptionOutput, $formatMessage = false, $tag = __CLASS__); + $this->checkBackend($backend, self::$expectedExceptionOutput, $formatMessage = false, $tag = 'Monolog'); } /** @@ -132,9 +132,7 @@ class LogTest extends IntegrationTestCase LoggerWrapper::doLog(self::TESTMESSAGE); - $tag = 'Piwik\Tests\Integration\Log\Fixture\LoggerWrapper'; - - $this->checkBackend($backend, self::TESTMESSAGE, $formatMessage = true, $tag); + $this->checkBackend($backend, self::TESTMESSAGE, $formatMessage = true, 'Monolog'); } /** @@ -159,9 +157,7 @@ class LogTest extends IntegrationTestCase LoggerWrapper::doLog(" \n ".self::TESTMESSAGE."\n\n\n \n"); - $tag = 'Piwik\Tests\Integration\Log\Fixture\LoggerWrapper'; - - $this->checkBackend($backend, self::TESTMESSAGE, $formatMessage = true, $tag); + $this->checkBackend($backend, self::TESTMESSAGE, $formatMessage = true, 'Monolog'); } /** @@ -176,7 +172,7 @@ class LogTest extends IntegrationTestCase Log::info(self::TESTMESSAGE); - $this->checkBackend('database', self::TESTMESSAGE, $formatMessage = true, $tag = __CLASS__); + $this->checkBackend('database', self::TESTMESSAGE, $formatMessage = true, $tag = 'Monolog'); } private function checkBackend($backend, $expectedMessage, $formatMessage = false, $tag = false) diff --git a/tests/PHPUnit/Unit/Log/Formatter/LineMessageFormatterTest.php b/plugins/Monolog/Test/Unit/Formatter/LineMessageFormatterTest.php similarity index 91% rename from tests/PHPUnit/Unit/Log/Formatter/LineMessageFormatterTest.php rename to plugins/Monolog/Test/Unit/Formatter/LineMessageFormatterTest.php index 9b9aac78b182c0874ab31027a19d4c316044a3c0..2b53633e6d53ea841b303b47f79131c2d4bc3bb3 100644 --- a/tests/PHPUnit/Unit/Log/Formatter/LineMessageFormatterTest.php +++ b/plugins/Monolog/Test/Unit/Formatter/LineMessageFormatterTest.php @@ -6,15 +6,14 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Unit\Log\Formatter; +namespace Piwik\Plugins\Monolog\Test\Unit\Formatter; use DateTime; -use Piwik\Log\Formatter\LineMessageFormatter; +use Piwik\Plugins\Monolog\Formatter\LineMessageFormatter; /** - * @group Core * @group Log - * @covers \Piwik\Log\Formatter\LineMessageFormatter + * @covers \Piwik\Plugins\Monolog\Formatter\LineMessageFormatter */ class LineMessageFormatterTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/PHPUnit/Unit/Log/Processor/ClassNameProcessorTest.php b/plugins/Monolog/Test/Unit/Processor/ClassNameProcessorTest.php similarity index 76% rename from tests/PHPUnit/Unit/Log/Processor/ClassNameProcessorTest.php rename to plugins/Monolog/Test/Unit/Processor/ClassNameProcessorTest.php index 2e002196e2d7c8342535574c046747036693763f..b1b307a4d7ed3a4acb9d331314f43a849dcf8552 100644 --- a/tests/PHPUnit/Unit/Log/Processor/ClassNameProcessorTest.php +++ b/plugins/Monolog/Test/Unit/Processor/ClassNameProcessorTest.php @@ -6,14 +6,13 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Unit\Log\Processor; +namespace Piwik\Plugins\Monolog\Test\Unit\Processor; -use Piwik\Log\Processor\ClassNameProcessor; +use Piwik\Plugins\Monolog\Processor\ClassNameProcessor; /** - * @group Core * @group Log - * @covers \Piwik\Log\Processor\ClassNameProcessor + * @covers \Piwik\Plugins\Monolog\Processor\ClassNameProcessor */ class ClassNameProcessorTest extends \PHPUnit_Framework_TestCase { @@ -33,7 +32,7 @@ class ClassNameProcessorTest extends \PHPUnit_Framework_TestCase $expected = array( 'extra' => array( 'foo' => 'bar', - 'class' => __CLASS__, + 'class' => 'Monolog', ), ); diff --git a/tests/PHPUnit/Unit/Log/Processor/ExceptionToTextProcessorTest.php b/plugins/Monolog/Test/Unit/Processor/ExceptionToTextProcessorTest.php similarity index 88% rename from tests/PHPUnit/Unit/Log/Processor/ExceptionToTextProcessorTest.php rename to plugins/Monolog/Test/Unit/Processor/ExceptionToTextProcessorTest.php index 54cff2ae37e364bd652f05f09d098e1f5162b759..5620325ef5cd79cdfd0c48f7fb56aec44716e4f2 100644 --- a/tests/PHPUnit/Unit/Log/Processor/ExceptionToTextProcessorTest.php +++ b/plugins/Monolog/Test/Unit/Processor/ExceptionToTextProcessorTest.php @@ -6,15 +6,14 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Unit\Log\Processor; +namespace Piwik\Plugins\Monolog\Test\Unit\Processor; use Piwik\Log; -use Piwik\Log\Processor\ExceptionToTextProcessor; +use Piwik\Plugins\Monolog\Processor\ExceptionToTextProcessor; /** - * @group Core * @group Log - * @covers \Piwik\Log\Processor\ExceptionToTextProcessor + * @covers \Piwik\Plugins\Monolog\Processor\ExceptionToTextProcessor */ class ExceptionToTextProcessorTest extends \PHPUnit_Framework_TestCase { @@ -48,7 +47,7 @@ class ExceptionToTextProcessorTest extends \PHPUnit_Framework_TestCase $result = $processor($record); $expected = array( - 'message' => __FILE__ . "(41): Hello world\n[stack trace]", + 'message' => __FILE__ . "(40): Hello world\n[stack trace]", 'context' => array( 'exception' => $exception, ), diff --git a/tests/PHPUnit/Unit/Log/Processor/RequestIdProcessorTest.php b/plugins/Monolog/Test/Unit/Processor/RequestIdProcessorTest.php similarity index 85% rename from tests/PHPUnit/Unit/Log/Processor/RequestIdProcessorTest.php rename to plugins/Monolog/Test/Unit/Processor/RequestIdProcessorTest.php index b9c809b6e6e3f635249d7f81c053528d41a6e014..3fc3c6a2f9bd511ecfc6ca0dbd9f3ccd42ca72dc 100644 --- a/tests/PHPUnit/Unit/Log/Processor/RequestIdProcessorTest.php +++ b/plugins/Monolog/Test/Unit/Processor/RequestIdProcessorTest.php @@ -6,15 +6,15 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Unit\Log\Processor; +namespace Piwik\Plugins\Monolog\Test\Unit\Processor; +use PHPUnit_Framework_TestCase; use Piwik\Common; -use Piwik\Log\Processor\RequestIdProcessor; +use Piwik\Plugins\Monolog\Processor\RequestIdProcessor; /** - * @group Core * @group Log - * @covers \Piwik\Log\Processor\RequestIdProcessor + * @covers \Piwik\Plugins\Monolog\Processor\RequestIdProcessor */ class RequestIdProcessorTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/PHPUnit/Unit/Log/Processor/SprintfProcessorTest.php b/plugins/Monolog/Test/Unit/Processor/SprintfProcessorTest.php similarity index 89% rename from tests/PHPUnit/Unit/Log/Processor/SprintfProcessorTest.php rename to plugins/Monolog/Test/Unit/Processor/SprintfProcessorTest.php index 7966b165de71dd6fe4461bd3d0096c5f6c8faf74..27ac6cbd0294e6ccf7490f6acb8bb16fc4e60b2b 100644 --- a/tests/PHPUnit/Unit/Log/Processor/SprintfProcessorTest.php +++ b/plugins/Monolog/Test/Unit/Processor/SprintfProcessorTest.php @@ -6,14 +6,13 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Unit\Log\Processor; +namespace Piwik\Plugins\Monolog\Test\Unit\Processor; -use Piwik\Log\Processor\SprintfProcessor; +use Piwik\Plugins\Monolog\Processor\SprintfProcessor; /** - * @group Core * @group Log - * @covers \Piwik\Log\Processor\SprintfProcessor + * @covers \Piwik\Plugins\Monolog\Processor\SprintfProcessor */ class SprintfProcessorTest extends \PHPUnit_Framework_TestCase { diff --git a/plugins/Monolog/config/config.php b/plugins/Monolog/config/config.php new file mode 100644 index 0000000000000000000000000000000000000000..02aff13313525d165c4552872fe9aede09cdeffe --- /dev/null +++ b/plugins/Monolog/config/config.php @@ -0,0 +1,99 @@ +<?php + +use Interop\Container\ContainerInterface; +use Monolog\Logger; +use Piwik\Log; + +return array( + + 'Psr\Log\LoggerInterface' => DI\object('Monolog\Logger') + ->constructor('piwik', DI\link('log.handlers'), DI\link('log.processors')), + + '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', + ); + $writerNames = array_map('trim', $writerNames); + $writers = array(); + foreach ($writerNames as $writerName) { + if (isset($classes[$writerName])) { + $writers[$writerName] = $c->get($classes[$writerName]); + } + } + return array_values($writers); + }), + + 'log.processors' => array( + DI\link('Piwik\Plugins\Monolog\Processor\ClassNameProcessor'), + DI\link('Piwik\Plugins\Monolog\Processor\RequestIdProcessor'), + DI\link('Piwik\Plugins\Monolog\Processor\ExceptionToTextProcessor'), + DI\link('Piwik\Plugins\Monolog\Processor\SprintfProcessor'), + DI\link('Monolog\Processor\PsrLogMessageProcessor'), + ), + + 'Piwik\Plugins\Monolog\Handler\FileHandler' => DI\object() + ->constructor(DI\link('log.file.filename'), DI\link('log.level')) + ->method('setFormatter', DI\link('Piwik\Plugins\Monolog\Formatter\LineMessageFormatter')), + + 'Piwik\Plugins\Monolog\Handler\DatabaseHandler' => DI\object() + ->constructor(DI\link('log.level')) + ->method('setFormatter', DI\link('Piwik\Plugins\Monolog\Formatter\LineMessageFormatter')), + + 'Piwik\Plugins\Monolog\Handler\WebNotificationHandler' => DI\object() + ->constructor(DI\link('log.level')) + ->method('setFormatter', DI\link('Piwik\Plugins\Monolog\Formatter\LineMessageFormatter')), + + 'log.level' => DI\factory(function (ContainerInterface $c) { + if ($c->has('ini.log.log_level')) { + $level = strtoupper($c->get('ini.log.log_level')); + if (!empty($level) && defined('Piwik\Log::'.strtoupper($level))) { + return Log::getMonologLevel(constant('Piwik\Log::'.strtoupper($level))); + } + } + return Logger::WARNING; + }), + + 'log.file.filename' => DI\factory(function (ContainerInterface $c) { + $logPath = $c->get('ini.log.logger_file_path'); + + // Absolute path + if (strpos($logPath, '/') === 0) { + return $logPath; + } + + // Remove 'tmp/' at the beginning + if (strpos($logPath, 'tmp/') === 0) { + $logPath = substr($logPath, strlen('tmp')); + } + + if (empty($logPath)) { + // Default log file + $logPath = '/logs/piwik.log'; + } + + $logPath = $c->get('path.tmp') . $logPath; + if (is_dir($logPath)) { + $logPath .= '/piwik.log'; + } + + return $logPath; + }), + + 'Piwik\Plugins\Monolog\Formatter\LineMessageFormatter' => DI\object() + ->constructor(DI\link('log.format')), + + 'log.format' => DI\factory(function (ContainerInterface $c) { + if ($c->has('ini.log.string_message_format')) { + return $c->get('ini.log.string_message_format'); + } + return '%level% %tag%[%datetime%] %message%'; + }), + +);