PHP Debug Log – Trace Errors

Hello Friends,

I read some where “Quality is not a product.. it is a process 😉 ”

I think process is hard-work we do and product is final result we get.

But how we make our process to get a good product, as a LAMP developer I think track processes “Debug Log” is good sort of tool for monitoring programs.

Trouble shooting is quite simple with Log Files. Log file can be used with analysis tools, it’s possible to get a good idea of where errors are coming from, how often errors return.

Here you can see a simple PHP script to trace PHP programs…

debugLog.php
………………….

function debugLog($log, $text)
{
$log_dir = dirname($log);
if( !file_exists($log_dir) or !is_dir($log_dir) or !is_writable($log_dir) )
return false;

$write_mode = ‘w’;
if( file_exists($log) && is_file($log) && is_writable($log) )
$write_mode = ‘a’;

if( !$handle = fopen($log, $write_mode) )
return false;

if( fwrite($handle, $text. “\n”) == FALSE )
return false;

@fclose($handle);
}

Debugging Tools:

http://xdebug.org/
http://valgrind.org/
http://www.php-debugger.com/dbg/
http://pecl.php.net/package/apd
http://pear.php.net/package/Benchmark/
http://code.google.com/p/webgrind/

We can’t imagine processes without Log File 😉