mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
parent
2c5d96e916
commit
7a4cabe5d3
2 changed files with 25 additions and 2 deletions
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue