Skip to content

Instantly share code, notes, and snippets.

@balbuf
Created September 25, 2018 17:00
Show Gist options
  • Save balbuf/0ca80d5c164c898855b8d574a8872765 to your computer and use it in GitHub Desktop.
Save balbuf/0ca80d5c164c898855b8d574a8872765 to your computer and use it in GitHub Desktop.
PHP debug function that provides basic trace info
<?php
function X($msg) {
$nameLen = 20;
$trace = debug_backtrace();
$caller = array_shift($trace);
$date = date('c');
list($ms) = explode(' ', microtime());
$line = str_pad($caller['line'], 4, '0', STR_PAD_LEFT);
$file = str_pad(substr(basename($caller['file'], '.php'), -$nameLen), $nameLen);
return "$file [$line] ($date $ms) $msg\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment