Merge pull request #2841 from cakephp/2.5-debugger-log

2.5 debugger log
This commit is contained in:
ADmad 2014-02-17 11:29:52 +05:30
commit 2d87a9922e
2 changed files with 32 additions and 9 deletions

View file

@ -455,18 +455,40 @@ TEXT;
Debugger::log('cool');
$result = file_get_contents(LOGS . 'debug.log');
$this->assertRegExp('/DebuggerTest\:\:testLog/i', $result);
$this->assertRegExp("/'cool'/", $result);
$this->assertContains('DebuggerTest::testLog', $result);
$this->assertContains("'cool'", $result);
unlink(LOGS . 'debug.log');
Debugger::log(array('whatever', 'here'));
$result = file_get_contents(LOGS . 'debug.log');
$this->assertRegExp('/DebuggerTest\:\:testLog/i', $result);
$this->assertRegExp('/\[main\]/', $result);
$this->assertRegExp('/array/', $result);
$this->assertRegExp("/'whatever',/", $result);
$this->assertRegExp("/'here'/", $result);
$this->assertContains('DebuggerTest::testLog', $result);
$this->assertContains('[main]', $result);
$this->assertContains('array', $result);
$this->assertContains("'whatever',", $result);
$this->assertContains("'here'", $result);
}
/**
* test log() depth
*
* @return void
*/
public function testLogDepth() {
if (file_exists(LOGS . 'debug.log')) {
unlink(LOGS . 'debug.log');
}
CakeLog::config('file', array('engine' => 'File', 'path' => TMP . 'logs' . DS));
$val = array(
'test' => array('key' => 'val')
);
Debugger::log($val, LOG_DEBUG, 0);
$result = file_get_contents(LOGS . 'debug.log');
$this->assertContains('DebuggerTest::testLog', $result);
$this->assertNotContains("/'val'/", $result);
unlink(LOGS . 'debug.log');
}
/**

View file

@ -184,12 +184,13 @@ class Debugger {
*
* @param mixed $var Variable or content to log
* @param integer $level type of log to use. Defaults to LOG_DEBUG
* @param int $depth The depth to output to. Defaults to 3.
* @return void
* @link http://book.cakephp.org/2.0/en/development/debugging.html#Debugger::log
*/
public static function log($var, $level = LOG_DEBUG) {
public static function log($var, $level = LOG_DEBUG, $depth = 3) {
$source = self::trace(array('start' => 1)) . "\n";
CakeLog::write($level, "\n" . $source . self::exportVar($var));
CakeLog::write($level, "\n" . $source . self::exportVar($var, $depth));
}
/**