From 7a4cabe5d3d608b4a0d77d53640b22024e25d487 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 16 Feb 2014 14:35:00 -0500 Subject: [PATCH 1/3] 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 --- lib/Cake/Test/Case/Utility/DebuggerTest.php | 22 +++++++++++++++++++++ lib/Cake/Utility/Debugger.php | 5 +++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/DebuggerTest.php b/lib/Cake/Test/Case/Utility/DebuggerTest.php index 4ff538f23..e8287aa7d 100644 --- a/lib/Cake/Test/Case/Utility/DebuggerTest.php +++ b/lib/Cake/Test/Case/Utility/DebuggerTest.php @@ -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 * diff --git a/lib/Cake/Utility/Debugger.php b/lib/Cake/Utility/Debugger.php index c2d4cfc76..92e624a7e 100644 --- a/lib/Cake/Utility/Debugger.php +++ b/lib/Cake/Utility/Debugger.php @@ -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)); } /** From 3919f93149c0bfe07567c05b1163ee4a9074dc09 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 16 Feb 2014 14:37:29 -0500 Subject: [PATCH 2/3] Use simpler assertions. --- lib/Cake/Test/Case/Utility/DebuggerTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/DebuggerTest.php b/lib/Cake/Test/Case/Utility/DebuggerTest.php index e8287aa7d..847974500 100644 --- a/lib/Cake/Test/Case/Utility/DebuggerTest.php +++ b/lib/Cake/Test/Case/Utility/DebuggerTest.php @@ -455,18 +455,18 @@ 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); } /** From cde93ca7b9cfa1c12c9a985cefc9c16cbdefa8bc Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 16 Feb 2014 21:37:28 -0500 Subject: [PATCH 3/3] 2.x needs to be compatible with PHP<5.4 --- lib/Cake/Test/Case/Utility/DebuggerTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/DebuggerTest.php b/lib/Cake/Test/Case/Utility/DebuggerTest.php index 847974500..57d699eb3 100644 --- a/lib/Cake/Test/Case/Utility/DebuggerTest.php +++ b/lib/Cake/Test/Case/Utility/DebuggerTest.php @@ -480,9 +480,9 @@ TEXT; } CakeLog::config('file', array('engine' => 'File', 'path' => TMP . 'logs' . DS)); - $val = [ - 'test' => ['key' => 'val'] - ]; + $val = array( + 'test' => array('key' => 'val') + ); Debugger::log($val, LOG_DEBUG, 0); $result = file_get_contents(LOGS . 'debug.log'); $this->assertContains('DebuggerTest::testLog', $result);