Debugging Function
This small function snippet is a easy way of keeping a log of events during a midgard session. Simply call debug_add("some text"); every time you want anything logged. It won't keep the log open to keep things small and simple.
Configuration
- $code_debugger_debugging
- Set this to nonzero if you want debuggin, to zero if you dont requrie it further. This way you can keep the debug calls in the system without having a large impact on the performance.
- $code_debugger_filename
- The path to the debugging file. Keep in mind that it will be opened with the permissions of the web server, so maybe something in /tmp is advisable here.
- $code_debugger_prefix
- The String prefix that gets before each line written in the log. For example, you can set this to the current element in the processing queue so you can see where the different lines are thrown.
Writing a line into the log
If you call debug_add("some text") the function will write the line "$code_debugger_prefix: . trim(some text)" into the logfile.
Code
<?php
function debug_add ($log) {
global $code_debugger_debugging;
global $code_debugger_filename;
global $code_debugger_prefix;
if ($code_debugger_debugging == 1) {
$file = fopen ($code_debugger_filename,"a+");
fputs ($file, $code_debugger_prefix . ": " . trim($log) . "\n");
fclose ($file);
}
}
$code_debugger_debugging = 1;
$code_debugger_filename = "/tmp/midgard.log";
$code_debugger_prefix = "code-global";
?>