/** * test config() with valid key name * * @return void */ public function testValidKeyName() { CakeLog::config('valid', array('engine' => 'FileLog')); $stream = CakeLog::stream('valid'); $this->assertInstanceOf('FileLog', $stream); CakeLog::drop('valid'); }
/** * Sets up a mocked logger stream * * @return void **/ public function setUp() { parent::setUp(); $class = $this->getMockClass('BaseLog'); CakeLog::config('queuetest', array('engine' => $class, 'types' => array('error'), 'scopes' => ['gearman'])); $this->logger = CakeLog::stream('queuetest'); Configure::write('Gearman', array()); }
/** * Sets up a mocked logger stream * * @return void **/ public function setUp() { parent::setUp(); $class = $this->getMockClass('BaseLog', array('write'), array(), 'SQSBaseLog'); CakeLog::config('queuetest', array('engine' => $class, 'types' => array('error', 'debug'), 'scopes' => array('sqs'))); $this->logger = CakeLog::stream('queuetest'); CakeLog::disable('stderr'); Configure::write('SQS', array()); }
/** * Sets up a mocked logger stream * * @return void **/ public function setUp() { parent::setUp(); $this->_root = Nodes\Environment::getRoot(); Nodes\Environment::setRoot('/var/www/test'); $class = $this->getMockClass('BaseLog'); CakeLog::config('queuetest', array('engine' => $class, 'types' => array('error'))); $this->logger = CakeLog::stream('queuetest'); }
public function testLog() { $stream = CakeLog::stream('error'); $engine = get_class($stream); $config = array_merge($stream->config(), compact('engine')); CakeLog::config('error', array_merge($config, array('engine' => 'FileLog', 'path' => TMP . 'tests' . DS))); $filepath = TMP . 'tests' . DS . 'error.log'; if (file_exists($filepath)) { unlink($filepath); } $this->assertTrue($this->Model->log('Test warning 1')); $this->assertTrue($this->Model->log(array('Test' => 'warning 2'))); $result = file($filepath); $this->assertRegExp('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Error: Test warning 1$/', $result[0]); $this->assertRegExp('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Error: Array$/', $result[1]); $this->assertRegExp('/^\\($/', $result[2]); $this->assertRegExp('/\\[Test\\] => warning 2$/', $result[3]); $this->assertRegExp('/^\\)$/', $result[4]); unlink($filepath); $this->assertTrue($this->Model->log('Test warning 1', LOG_WARNING)); $this->assertTrue($this->Model->log(array('Test' => 'warning 2'), LOG_WARNING)); $result = file($filepath); $this->assertRegExp('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Warning: Test warning 1$/', $result[0]); $this->assertRegExp('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Warning: Array$/', $result[1]); $this->assertRegExp('/^\\($/', $result[2]); $this->assertRegExp('/\\[Test\\] => warning 2$/', $result[3]); $this->assertRegExp('/^\\)$/', $result[4]); unlink($filepath); CakeLog::config('error', array_merge($config, array('engine' => 'FileLog', 'path' => TMP . 'tests' . DS, 'scopes' => array('some_scope')))); $this->assertTrue($this->Model->log('Test warning 1', LOG_WARNING)); $this->assertTrue(!file_exists($filepath)); $this->assertTrue($this->Model->log('Test warning 1', LOG_WARNING, 'some_scope')); $result = file($filepath); $this->assertRegExp('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Warning: Test warning 1$/', $result[0]); CakeLog::config('error', $config); }
/** * test LogError() * * @return void */ public function testLogError() { @unlink(LOGS . 'error.log'); // disable stderr output for this test if (CakeLog::stream('stderr')) { CakeLog::disable('stderr'); } LogError('Testing LogError() basic function'); LogError("Testing with\nmulti-line\nstring"); if (CakeLog::stream('stderr')) { CakeLog::enable('stderr'); } $result = file_get_contents(LOGS . 'error.log'); $this->assertRegExp('/Error: Testing LogError\\(\\) basic function/', $result); $this->assertNotRegExp("/Error: Testing with\nmulti-line\nstring/", $result); $this->assertRegExp('/Error: Testing with multi-line string/', $result); }
/** * Tests that _useLogger works properly * * @return void */ public function testProtectedUseLogger() { CakeLog::drop('stdout'); CakeLog::drop('stderr'); $this->Shell->useLogger(true); $this->assertNotEmpty(CakeLog::stream('stdout')); $this->assertNotEmpty(CakeLog::stream('stderr')); $this->Shell->useLogger(false); $this->assertFalse(CakeLog::stream('stdout')); $this->assertFalse(CakeLog::stream('stderr')); }
/** * Restore original scopes on all loggers */ public function _restoresForSetup() { foreach (CakeLog::configured() as $name) { $logger = CakeLog::stream($name); if (!method_exists($logger, 'config')) { continue; } $config = $logger->config(); if (!array_key_exists('scopes_backup', $config)) { continue; } $config['scopes'] = $config['scopes_backup']; unset($config['scopes_backup']); $logger->config($config); } }