diff --git a/gulliver/system/class.monologProvider.php b/gulliver/system/class.monologProvider.php index c3c854d65..5b876a596 100644 --- a/gulliver/system/class.monologProvider.php +++ b/gulliver/system/class.monologProvider.php @@ -241,6 +241,7 @@ class MonologProvider */ public function setStream($fileLog) { + // ONLY initialize a new RotatingFileHandler if the fileLog is DIFFERENT. //Set Routating Handler $this->streamRoutating = new RotatingFileHandler($this->getPathFile() . $fileLog, $this->getMaxFiles(), @@ -446,7 +447,6 @@ class MonologProvider { if (self::$instance === null) { self::$instance = new MonologProvider($channel, $fileLog, $readLoggingLevel); - } else { self::$instance->setConfig($channel, $fileLog, $readLoggingLevel); } return self::$instance; @@ -489,4 +489,12 @@ class MonologProvider return false; } } + + /** + * Set the instance property + */ + static function setInstance($instance) + { + self::$instance = $instance; + } } \ No newline at end of file diff --git a/tests/unit/gulliver/system/MonologProviderTest.php b/tests/unit/gulliver/system/MonologProviderTest.php index 47d77fef8..dc7f60748 100644 --- a/tests/unit/gulliver/system/MonologProviderTest.php +++ b/tests/unit/gulliver/system/MonologProviderTest.php @@ -213,4 +213,35 @@ class MonologProviderTest extends TestCase // Check that the CRITICAL was registered $this->assertTrue($res); } -} + + /** + * It tests the getSingleton method + * + * @covers ::getSingleton + * @test + */ + public function it_test_the_get_singleton_method() + { + // Call the getSingleton method twice + $log = MonologProvider::getSingleton('Channel Test', 'processmaker.log', true); + $log = MonologProvider::getSingleton('Channel Test', 'processmaker.log', true); + MonologProvider::setInstance("something"); + // Set level debug to "INFO" + $log->setLevelDebug('INFO'); + // This asserts the lever debug is 200 + $this->assertEquals($log->getLevelDebug(), 200); + // Set level debug to "UNDEFINED" + $log->setLevelDebug('UNDEFINED'); + // This asserts there is no level debug + $this->assertEmpty($log->getLevelDebug()); + } + + /** + * It calls the tearDown method + */ + public function tearDown() + { + parent::tearDown(); + MonologProvider::setInstance(null); + } +} \ No newline at end of file