Table of Contents

Debugging Your Code

Cake has three standard debug levels, set by using the DEBUG constant in core.php (to be found in the “app\config” sub-folder) - set this to 0 for production use, 1 for debugging during development, 2 for debugging with SQL output and 3 for full debug with SQL, and dump of the current object. In version 0.10 level 1 is default (see source code comments in the file for the most recent details).

As well as this, Cake also has a global debug function. It outputs the passed variable in a readable format. If the debug level setting is 0 then nothing will be output.

$variable = array('one'=>1, 'two'=>2);
debug( $variable );

produces

Array(
'one' => 1,
'two' => 2,
)

As you can see, debug() is a very thin wrapper around print_r() in PHP.

Logging Errors

incomplete - this is a placeholder only - if you have any information please add it here! All classes inherit behaviour from the Object class, this class allows for errors to be logged to a log file.

    function log ($msg, $type=LOG_ERROR)

Called as $this→log(’message to write to log file’)

LOG_ERROR types

  • LOG_DEBUG defined in PHP. See http://ca3.php.net/syslog. Output will go in tmp/logs/debug.log
  • LOG_ERROR defined in cake/libs/log.php. Output will go in tmp/logs/error.log

Location of Log Files

  • ROOT
    • app
    • cake
    • tmp
      • logs your logs here
    • vendors

By what I have seen in object.php and log.php, you can have two log files at the same time, error.log (default) and debug.log.

 
tutorials/debugging_your_code.txt · Last modified: 2006/02/13 17:51 by laplo