PHP logging using Javascript/HackerConsole

Every PHP developer faces script debug issues. Simple way of var_dump variable content to HTML is of course the simplest but not convenient. It crashes site design and is not suitable for large amount of data. I'd like to advertise nice tool to solve this issue. HackerConsole by dkLab, it is simple, fast and easy to use. Guess author was inspired by famous Quake tilde console invoked by Ctrl+~. This lib works same way. You output all variables using debug() function, after page is loaded all debug output is accessible by pressing Ctrl+~ DEMO, CLICK HERE! Usage is very simple, here code I use for initialization.
if ($config['debug']) {
 require_once "lib/HackerConsole/Main.php";
 new Debug_HackerConsole_Main(true);
}
function debug($vr) {if (class_exists("Debug_HackerConsole_Main")) Debug_HackerConsole_Main::out($vr);}
I use global debug flag, since I do not want debug messages on production servers. In program code simple debug messages output by using lines:
debug("This is string");
debug( array("This is array",1,2,3) );
All output data is going to JavaScript array which is not visible by default and is shown only on key combination. If your database layer supports SQL logging it is very easy to setup it in the way to show all SQL statements executed during script execution. Also I disable debug console for AJAX requests for obvious reasons:
if (strpos($_SERVER["REQUEST_URI"],"ajax") !== false)
   Debug_HackerConsole_Main::disable();
Recommended!!! Download it from

Leave a Reply

Your email address will not be published.