Add depth to log().

Much like dump() it is handy to be able to control the depth variables
are dumped out when logged.

Refs #2834
This commit is contained in:
mark_story 2014-02-16 14:35:00 -05:00
parent 2c5d96e916
commit 7a4cabe5d3
2 changed files with 25 additions and 2 deletions

View file

@ -469,6 +469,28 @@ TEXT;
$this->assertRegExp("/'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 = [
'test' => ['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');
}
/**
* testDump method
*

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));
}
/**