mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 17:16:18 +00:00
Merge pull request #2841 from cakephp/2.5-debugger-log
2.5 debugger log
This commit is contained in:
commit
2d87a9922e
2 changed files with 32 additions and 9 deletions
|
@ -455,18 +455,40 @@ TEXT;
|
||||||
|
|
||||||
Debugger::log('cool');
|
Debugger::log('cool');
|
||||||
$result = file_get_contents(LOGS . 'debug.log');
|
$result = file_get_contents(LOGS . 'debug.log');
|
||||||
$this->assertRegExp('/DebuggerTest\:\:testLog/i', $result);
|
$this->assertContains('DebuggerTest::testLog', $result);
|
||||||
$this->assertRegExp("/'cool'/", $result);
|
$this->assertContains("'cool'", $result);
|
||||||
|
|
||||||
unlink(LOGS . 'debug.log');
|
unlink(LOGS . 'debug.log');
|
||||||
|
|
||||||
Debugger::log(array('whatever', 'here'));
|
Debugger::log(array('whatever', 'here'));
|
||||||
$result = file_get_contents(LOGS . 'debug.log');
|
$result = file_get_contents(LOGS . 'debug.log');
|
||||||
$this->assertRegExp('/DebuggerTest\:\:testLog/i', $result);
|
$this->assertContains('DebuggerTest::testLog', $result);
|
||||||
$this->assertRegExp('/\[main\]/', $result);
|
$this->assertContains('[main]', $result);
|
||||||
$this->assertRegExp('/array/', $result);
|
$this->assertContains('array', $result);
|
||||||
$this->assertRegExp("/'whatever',/", $result);
|
$this->assertContains("'whatever',", $result);
|
||||||
$this->assertRegExp("/'here'/", $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');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -184,12 +184,13 @@ class Debugger {
|
||||||
*
|
*
|
||||||
* @param mixed $var Variable or content to log
|
* @param mixed $var Variable or content to log
|
||||||
* @param integer $level type of log to use. Defaults to LOG_DEBUG
|
* @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
|
* @return void
|
||||||
* @link http://book.cakephp.org/2.0/en/development/debugging.html#Debugger::log
|
* @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";
|
$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…
Add table
Reference in a new issue