Permalink
Browse files

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
  • Loading branch information...
1 parent 2c5d96e commit 7a4cabe5d3d608b4a0d77d53640b22024e25d487 @markstory markstory committed Feb 16, 2014
Showing with 25 additions and 2 deletions.
  1. +22 −0 lib/Cake/Test/Case/Utility/DebuggerTest.php
  2. +3 −2 lib/Cake/Utility/Debugger.php
@@ -470,6 +470,28 @@ public function testLog() {
}
/**
+ * 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
*
* @return void
@@ -184,12 +184,13 @@ public static function dump($var, $depth = 3) {
*
* @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));
}
/**

0 comments on commit 7a4cabe

Please sign in to comment.