Logging > CakePHP > Simplify debugging

When you are dealing with a complicated programming task, the best way to simplify is to create clear and concise logs

Follow these isntructions how to create a great logging system to you can identify what your program is doing and find bugs quickly and efficiently. 


# 1 > Create function

Create this PHP function which will be used to call the LOGS

$filename = which name of file to create in CakePHP tmp location
$message = What to display in the log
$newLine = If you want to put many logs onto one line (keeps your logs clean) put FALSE here

public function writeToLog($filename, $message, $newLine = true) {
if ($newLine) {
$message = "\n".date('Ymd-His').' > '.$message;
} else {
$message = ' > '.$message;
file_put_contents(APP.'tmp/logs/'.$filename, $message, FILE_APPEND);


# 2 > Call the log

Then simply place calls to the log to identify what your program is doing

If you want to see a new line each time

$this->writeToLog('Simulators', 'Started at the top found '.$variableFromCode.' db rows', TRUE);

If you want to keep all the info on the same line

$this->writeToLog('Simulators', 'Started at the top found '.$variableFromCode.' db rows', FALSE);


Other Instructions

Below are many other instructions that show you how to use your UpdateCase application