| 1 |
<?php |
| 2 |
|
| 3 |
namespace BitCode\BitForm\Core\Util; |
| 4 |
|
| 5 |
final class Log { |
| 6 |
public static function get_backtrace_info() { |
| 7 |
$trace = debug_backtrace(); |
| 8 |
|
| 9 |
$file = $trace[1]['file']; |
| 10 |
$class = $trace[2]['class']; |
| 11 |
$func = $trace[2]['function']; |
| 12 |
$type = $trace[2]['type']; |
| 13 |
$line = $trace[1]['line']; |
| 14 |
|
| 15 |
$output = sprintf( |
| 16 |
'%s%s%s() at %s on line %s', |
| 17 |
$class, |
| 18 |
$type, |
| 19 |
$func, |
| 20 |
$file, |
| 21 |
$line |
| 22 |
); |
| 23 |
|
| 24 |
return $output; |
| 25 |
} |
| 26 |
|
| 27 |
public static function debug_log($log) { |
| 28 |
$trace_info = self::get_backtrace_info(); |
| 29 |
if (WP_DEBUG === true) { |
| 30 |
if (is_array($log) || is_object($log)) { |
| 31 |
if (is_array($log)) { |
| 32 |
$log['trace'] = $trace_info; |
| 33 |
} else { |
| 34 |
$log->trace = $trace_info; |
| 35 |
} |
| 36 |
$log_msg = print_r($log, true); |
| 37 |
} else { |
| 38 |
$log_msg = $log . ' in ' . $trace_info; |
| 39 |
} |
| 40 |
|
| 41 |
error_log($log_msg); |
| 42 |
// var_dump($log_msg); |
| 43 |
} |
| 44 |
// die; |
| 45 |
} |
| 46 |
} |
| 47 |
|