| @@ -1,10 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace BitCode\BitForm\Core\Util; |
| 4 | 4 | |
| 5 | -final class Log { | |
| 6 | - public static function get_backtrace_info() { | |
| 5 | +final class Log | |
| 6 | +{ | |
| 7 | + public static function get_backtrace_info() | |
| 8 | + { | |
| 7 | 9 | $trace = debug_backtrace(); |
| 8 | 10 | |
| 9 | 11 | $file = $trace[1]['file']; |
| 10 | 12 | $class = $trace[2]['class']; |
| @@ -23,9 +25,10 @@ | ||
| 23 | 25 | |
| 24 | 26 | return $output; |
| 25 | 27 | } |
| 26 | 28 | |
| 27 | - public static function debug_log($log) { | |
| 29 | + public static function debug_log($log) | |
| 30 | + { | |
| 28 | 31 | $trace_info = self::get_backtrace_info(); |
| 29 | 32 | if (WP_DEBUG === true) { |
| 30 | 33 | if (is_array($log) || is_object($log)) { |
| 31 | 34 | if (is_array($log)) { |
| @@ -38,9 +41,27 @@ | ||
| 38 | 41 | $log_msg = $log . ' in ' . $trace_info; |
| 39 | 42 | } |
| 40 | 43 | |
| 41 | 44 | error_log($log_msg); |
| 42 | - // var_dump($log_msg); | |
| 43 | 45 | } |
| 44 | - // die; | |
| 46 | + } | |
| 47 | + | |
| 48 | + public static function print($log, $path = '', $fileName = 'print.log', $fileOpenMode = 'a') | |
| 49 | + { | |
| 50 | + $rootDir = BITFORMS_CONTENT_DIR; | |
| 51 | + $path = trim($path, '/'); | |
| 52 | + $pathArr = explode('/', $path); // like "fieldname/user => [Fieldname, user] | |
| 53 | + foreach ($pathArr as $d) { | |
| 54 | + $rootDir .= $d . DIRECTORY_SEPARATOR; | |
| 55 | + if (!realpath($rootDir)) { | |
| 56 | + wp_mkdir_p($rootDir); | |
| 57 | + } | |
| 58 | + } | |
| 59 | + $fullPath = $rootDir . $fileName; | |
| 60 | + if ('a' === $fileOpenMode) { | |
| 61 | + FileHandler::appendFile($fullPath, $log); | |
| 62 | + } else { | |
| 63 | + FileHandler::writeFile($fullPath, $log); | |
| 64 | + } | |
| 65 | + return true; | |
| 45 | 66 | } |
| 46 | 67 | } |