PluginProbe
RabbitLoader / 3.0.3
RabbitLoader v3.0.3
4.0.2 4.0.1 4.0 3.2.0 3.1.1 3.1.0 3.0.5 3.0.3 3.0.4 2.17.1 2.17.2 2.17.3 2.17.4 2.17.5 2.17.6 2.17.7 2.18.0 2.18.1 2.18.2 2.18.3 2.18.4 2.18.5 2.18.6 2.18.7 2.18.8 All 129 releases
rabbit-loader / inc / RabbitLoader / SDK / Exc.php

Exc.php in RabbitLoader 3.0.3, at inc/RabbitLoader/SDK/Exc.php

57 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace RabbitLoader\SDK;
4
5 class Exc extends \Exception
6 {
7 private static $log;
8 private static $debug = false;
9
10 public static function setFile($rootDir, $debug)
11 {
12 self::$log = new File(rtrim($rootDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'error.log');
13 self::$debug = $debug;
14 }
15
16 public static function catch($e, $data = [], $limit = 8)
17 {
18 $msg = [];
19 try {
20 $msg['time'] = date("c");
21
22 if (function_exists('is_wp_error') && is_wp_error($e)) {
23 $msg['msg'] = $e->get_error_message();
24 } else if ($e instanceof \Exception || $e instanceof \Throwable) {
25 $msg['msg'] = $e->getMessage();
26 $msg['file'] = $e->getFile();
27 $msg['line'] = $e->getLine();
28 } else {
29 $msg['msg'] = $e;
30 }
31 if ($limit > 8) {
32 $limit = 8;
33 }
34 $msg['backtrace'] = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, $limit);
35 $msg['server'] = $_SERVER;
36
37 $msgStr = json_encode($msg);
38 self::$log->fac($msgStr);
39 if (self::$debug) {
40 echo $msgStr;
41 error_log($msgStr);
42 }
43 } catch (\Throwable $e) {
44 if (self::$debug) {
45 echo $e->getMessage();
46 }
47 }
48 }
49
50 public static function &getAndClean()
51 {
52 $data = self::$log->fgc();
53 self::$log->unlink();
54 return $data;
55 }
56 }
57