| @@ -16,36 +16,33 @@ | ||
| 16 | 16 | * Requires WP_GURUS_DEBUG = true, define it in your wp-config.php file. |
| 17 | 17 | * Set WP_DEBUG to true, and WP_DEBUG_DISPLAY to false (so no errors are printed to screen), and WP_DEBUG_LOG to true so messages are logged to wp-content/debug.log file. |
| 18 | 18 | */ |
| 19 | 19 | function debug_msg($message, $prefix='', $trace=0) { |
| 20 | - if (true === WP_GURUS_DEBUG) { | |
| 21 | - global $debug_msg_last_line,$debug_msg_last_file; | |
| 22 | - $backtrace = debug_backtrace(); | |
| 23 | - $file = $backtrace[0]['file']; | |
| 24 | - $line = $backtrace[0]['line']; | |
| 25 | - $files = explode('/',$file); | |
| 26 | - $dirs = explode('/',plugin_dir_path( __FILE__ )); | |
| 27 | - $files = array_diff($files,$dirs); | |
| 28 | - $file = implode('/',$files); | |
| 29 | - $msg='DEBUG_MSG:'.($trace?' --------------- ':''); | |
| 30 | - if (is_array($message) || is_object($message)) { | |
| 31 | - $msg.=$prefix.print_r($message, true); | |
| 32 | - } else { | |
| 33 | - $msg.=$prefix.$message; | |
| 20 | + if (true === WP_GURUS_DEBUG) { | |
| 21 | + global $debug_msg_last_line,$debug_msg_last_file; | |
| 22 | + $backtrace = debug_backtrace(); | |
| 23 | + $file = $backtrace[0]['file']; | |
| 24 | + $files = explode('/',$file); | |
| 25 | + $dirs = explode('/',plugin_dir_path( __FILE__ )); | |
| 26 | + $files = array_diff($files,$dirs); | |
| 27 | + $file = implode('/',$files); | |
| 28 | + $line = $backtrace[0]['line']; | |
| 29 | + $msg='DEBUG_MSG: '.PHP_EOL; | |
| 30 | + if(true===$trace || ($file != $debug_msg_last_file && $line != $debug_msg_last_line)){ | |
| 31 | + if($trace===true) $trace = sizeof($backtrace); | |
| 32 | + for($idx=$trace; $idx>0; $idx--){ | |
| 33 | + $msg.=" [".$backtrace[$idx]['line']."]->/".$backtrace[$idx]['file'].PHP_EOL; | |
| 34 | + } | |
| 35 | + $msg.= " [".$line."]./".$file.PHP_EOL; | |
| 36 | + $debug_msg_last_file=$file; | |
| 37 | + $debug_msg_last_line=$line; | |
| 38 | + } | |
| 39 | + | |
| 40 | + if (is_array($message) || is_object($message)) { | |
| 41 | + $msg.=" + ".$prefix.print_r($message, true); | |
| 42 | + } else { | |
| 43 | + $msg.=" + ".$prefix.$message; | |
| 44 | + } | |
| 45 | + error_log($msg); | |
| 34 | 46 | } |
| 35 | - if(true===$trace || ($file != $debug_msg_last_file && $line != $debug_msg_last_line)){ | |
| 36 | - if($trace===true){ | |
| 37 | - $trace = sizeof($backtrace); | |
| 38 | - $msg.=PHP_EOL; | |
| 39 | - } | |
| 40 | - for($idx=($trace-1); $idx>0; $idx--){ | |
| 41 | - $msg.='['.$backtrace[$idx]['line'].']->/'.$backtrace[$idx]['file'].PHP_EOL; | |
| 42 | - } | |
| 43 | - $msg.= ($trace?'':PHP_EOL)."/$file:$line"; | |
| 44 | - $debug_msg_last_file=$file; | |
| 45 | - $debug_msg_last_line=$line; | |
| 46 | - if($trace) $msg.=PHP_EOL.'-----------------------------------------------------'; | |
| 47 | - } | |
| 48 | - error_log($msg); | |
| 49 | - } | |
| 50 | 47 | } |
| 51 | 48 | } ?> |