public function testEnabled() { $log = new Slim_Log(new MyWriter()); $this->assertTrue($log->isEnabled()); //<-- Default case $log->setEnabled(true); $this->assertTrue($log->isEnabled()); $log->setEnabled(false); $this->assertFalse($log->isEnabled()); }
/** * Get application Log (lazy-loaded) * @return Slim_Log */ public function getLog() { if (!isset($this->log)) { $this->log = new Slim_Log(); $this->log->setEnabled($this->config('log.enable')); $logger = $this->config('log.logger'); if ($logger) { $this->log->setLogger($logger); } else { $this->log->setLogger(new Slim_Logger($this->config('log.path'), $this->config('log.level'))); } } return $this->log; }
/** * Constructor * @param array $userSettings Key-Value array of application settings * @return void */ public function __construct($userSettings = array()) { //Setup Slim application $this->environment = Slim_Environment::getInstance(); $this->request = new Slim_Http_Request($this->environment); $this->response = new Slim_Http_Response(); $this->router = new Slim_Router($this->request->getResourceUri()); $this->settings = array_merge(self::getDefaultSettings(), $userSettings); $this->middleware = array($this); $this->add(new Slim_Middleware_Flash()); $this->add(new Slim_Middleware_MethodOverride()); //Determine application mode $this->getMode(); //Setup view $this->view($this->config('view')); //Make default if first instance if (is_null(self::getInstance())) { $this->setName('default'); } //Set default logger that writes to stderr (may be overridden with middleware) $logWriter = $this->config('log.writer'); if (!$logWriter) { $logWriter = new Slim_LogWriter($this->environment['slim.errors']); } $log = new Slim_Log($logWriter); $log->setEnabled($this->config('log.enabled')); $log->setLevel($this->config('log.level')); $this->environment['slim.log'] = $log; //Set global error handler set_error_handler(array('Slim', 'handleErrors')); }
/** * Test Log adapter methods * * Pre-conditions * Log instantiated with MyLogger instance * * Post-conditions: * A) All Log adapter methods return expected results * B) All Log adapter methods return false */ public function testLoggerMethods() { $log = new Slim_Log(); $logger = new MyLogger(); $log->setLogger($logger); //Case A: Logging enabled $this->assertEquals('debug', $log->debug('Test')); $this->assertEquals('info', $log->info('Test')); $this->assertEquals('warn', $log->warn('Test')); $this->assertEquals('error', $log->error('Test')); $this->assertEquals('fatal', $log->fatal('Test')); //Case B: Logging disabled $log->setEnabled(false); $this->assertFalse($log->debug('Test')); $this->assertFalse($log->info('Test')); $this->assertFalse($log->warn('Test')); $this->assertFalse($log->error('Test')); $this->assertFalse($log->fatal('Test')); }