| 1 |
<?php |
| 2 |
/** |
| 3 |
* Error logging and notices |
| 4 |
* @since 1.0.0 |
| 5 |
* @var string $message to log if in debug mode |
| 6 |
*/ |
| 7 |
defined('WP_GURUS_DEBUG') || define('WP_GURUS_DEBUG', false); |
| 8 |
|
| 9 |
if( !function_exists('debug_msg') ){ |
| 10 |
if (true === WP_GURUS_DEBUG) { |
| 11 |
$debug_msg_last_line=''; |
| 12 |
$debug_msg_last_file=''; |
| 13 |
} |
| 14 |
function debug_msg($message, $prefix='', $trace=0) { |
| 15 |
if (true === WP_GURUS_DEBUG) { |
| 16 |
global $debug_msg_last_line,$debug_msg_last_file; |
| 17 |
$backtrace = debug_backtrace(); |
| 18 |
$file = $backtrace[0]['file']; |
| 19 |
$files = explode('/',$file); |
| 20 |
$dirs = explode('/',plugin_dir_path( __FILE__ )); |
| 21 |
$files = array_diff($files,$dirs); |
| 22 |
$file = implode('/',$files); |
| 23 |
$line = $backtrace[0]['line']; |
| 24 |
$msg='DEBUG_MSG: '.PHP_EOL; |
| 25 |
if(true===$trace || ($file != $debug_msg_last_file && $line != $debug_msg_last_line)){ |
| 26 |
if($trace===true) $trace = sizeof($backtrace); |
| 27 |
for($idx=$trace; $idx>0; $idx--){ |
| 28 |
$msg.=" [".$backtrace[$idx]['line']."]->/".$backtrace[$idx]['file'].PHP_EOL; |
| 29 |
} |
| 30 |
$msg.= " [".$line."]./".$file.PHP_EOL; |
| 31 |
$debug_msg_last_file=$file; |
| 32 |
$debug_msg_last_line=$line; |
| 33 |
} |
| 34 |
|
| 35 |
if (is_array($message) || is_object($message)) { |
| 36 |
$msg.=" + ".$prefix.print_r($message, true); |
| 37 |
} else { |
| 38 |
$msg.=" + ".$prefix.$message; |
| 39 |
} |
| 40 |
error_log($msg); |
| 41 |
} |
| 42 |
} |
| 43 |
} ?> |
| 44 |
|