Created
September 25, 2018 17:00
-
-
Save balbuf/0ca80d5c164c898855b8d574a8872765 to your computer and use it in GitHub Desktop.
PHP debug function that provides basic trace info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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