diff --git a/library/Icinga/Application/Logger.php b/library/Icinga/Application/Logger.php index fd246c26f..120a7f655 100755 --- a/library/Icinga/Application/Logger.php +++ b/library/Icinga/Application/Logger.php @@ -120,14 +120,15 @@ final class Logger { $this->clearLog(); try { - if ($config->debug && $config->debug->enable == 1) { + if ($config->debug && $config->debug->enable == '1') { $this->setupDebugLog($config); } } catch (ConfigurationError $e) { $this->warn('Could not create debug log: ' . $e->getMessage()); } - - $this->setupLog($config); + if ($config->get('enable', '1') != '0') { + $this->setupLog($config); + } $this->flushQueue(); return $this; diff --git a/test/php/regression/Regression4595Test.php b/test/php/regression/Regression4595Test.php new file mode 100644 index 000000000..17cf0111a --- /dev/null +++ b/test/php/regression/Regression4595Test.php @@ -0,0 +1,65 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + + +namespace Tests\Icinga\Regression; + +use \Icinga\Test\BaseTestCase; +use \Icinga\Application\Logger; +use \Zend_Config; + +require_once 'Zend/Log.php'; +require_once 'Zend/Config.php'; +require_once 'Zend/Log/Writer/Mock.php'; +require_once 'Zend/Log/Writer/Null.php'; +require_once 'Zend/Log/Filter/Priority.php'; + +require_once realpath(__DIR__ . '/../../../library/Icinga/Test/BaseTestCase.php'); +require_once realpath(BaseTestCase::$libDir.'/Application/Logger.php'); + +/** + * Bug 4595 : "If log disabled, default target (./var/log) is not writable / no path exist" + * + * This is caused because the logger ignored the 'enable' parameter + */ +class Regression4595 extends BaseTestCase { + + public function testDisableLogging() + { + $cfg = new Zend_Config( + array( + 'enable' => '0', + 'type' => 'mock', + 'target' => 'target2' + ) + ); + $logger = new Logger($cfg); + $writers = $logger->getWriters(); + $this->assertEquals(0, count($writers), 'Assert that loggers aren\'t registered when "enable" is set to false'); + } +} \ No newline at end of file