@@ -27,9 +27,53 @@ public function __construct()
2727 * @author Syed Faisal <sfkazmi0@gmail.com>
2828 * @param \Throwable $exception
2929 */
30- public function prepare (\Throwable $ exception )
30+ public function prepareException (\Throwable $ exception )
3131 {
32- return $ this ->getExceptionData ($ exception );
32+ $ data = $ this ->getRequestInfo ($ exception );
33+
34+ $ data ['exception ' ] = $ exception ->getMessage ();
35+ $ data ['class ' ] = get_class ($ exception );
36+ $ data ['file ' ] = $ exception ->getFile ();
37+ $ data ['line ' ] = $ exception ->getLine ();
38+ $ data ['error ' ] = $ exception ->getTraceAsString ();
39+ $ data ['trace_with_details ' ] = $ this ->prepareTraceData ($ exception ->getTrace ());
40+
41+ $ count = config ('larvabug.lines_count ' );
42+
43+ if (!$ count || $ count > 12 ) {
44+ $ count = 10 ;
45+ }
46+
47+ $ lines = file ($ data ['file ' ]);
48+ $ data ['executor ' ] = [];
49+
50+ for ($ i = -1 * abs ($ count ); $ i <= abs ($ count ); $ i ++) {
51+ $ data ['executor ' ][] = $ this ->getLineInfo ($ lines , $ data ['line ' ], $ i );
52+ }
53+
54+ $ data ['executor ' ] = array_filter ($ data ['executor ' ]);
55+
56+ // to make symfony exception more readable
57+ if ($ data ['class ' ] == 'Symfony\Component\Debug\Exception\FatalErrorException ' ) {
58+ preg_match ("~^(.+)' in ~ " , $ data ['exception ' ], $ matches );
59+ if (isset ($ matches [1 ])) {
60+ $ data ['exception ' ] = $ matches [1 ];
61+ }
62+ }
63+
64+ return $ data ;
65+ }
66+
67+ public function prepareLogData (string $ message ,array $ meta = [])
68+ {
69+ $ data = $ this ->getRequestInfo ();
70+ $ data ['exception ' ] = $ message ;
71+ $ data ['class ' ] = 'Log Information ' ;
72+ $ data ['type ' ] = 'log ' ;
73+ $ data ['meta_data ' ] = $ meta ;
74+
75+ return $ data ;
76+
3377 }
3478
3579 /**
@@ -38,13 +82,10 @@ public function prepare(\Throwable $exception)
3882 * @param \Throwable $exception
3983 * @return array
4084 */
41- private function getExceptionData ( \ Throwable $ exception )
85+ private function getRequestInfo ( )
4286 {
4387 $ data = [];
4488
45- $ data ['exception ' ] = $ exception ->getMessage ();
46- $ data ['class ' ] = get_class ($ exception );
47- $ data ['file ' ] = $ exception ->getFile ();
4889 $ data ['php_version ' ] = PHP_VERSION ;
4990 $ data ['server_ip ' ] = $ _SERVER ['SERVER_ADDR ' ] ?? null ;
5091 $ data ['environment ' ] = App::environment ();
@@ -56,7 +97,6 @@ private function getExceptionData(\Throwable $exception)
5697 $ data ['fullUrl ' ] = Request::fullUrl ();
5798 $ data ['url ' ] = Request::path ();
5899 $ data ['userIp ' ] = Request::ip ();
59- $ data ['line ' ] = $ exception ->getLine ();
60100 $ data ['date_time ' ] = date ("Y-m-d H:i:s " );
61101 $ data ['session_id ' ] = Session::getId ();
62102 $ data ['storage ' ] = [
@@ -76,34 +116,8 @@ private function getExceptionData(\Throwable $exception)
76116 'HEADERS ' => $ this ->filterBlackList (Request::header ()),
77117 ];
78118 $ data ['auth_user ' ] = $ this ->getAuthUser ();
79- $ data ['error ' ] = $ exception ->getTraceAsString ();
80- $ data ['trace_with_details ' ] = $ this ->prepareTraceData ($ exception ->getTrace ());
81-
82119 $ data ['storage ' ] = array_filter ($ data ['storage ' ]);
83120
84- $ count = config ('larvabug.lines_count ' );
85-
86- if (!$ count || $ count > 12 ) {
87- $ count = 10 ;
88- }
89-
90- $ lines = file ($ data ['file ' ]);
91- $ data ['executor ' ] = [];
92-
93- for ($ i = -1 * abs ($ count ); $ i <= abs ($ count ); $ i ++) {
94- $ data ['executor ' ][] = $ this ->getLineInfo ($ lines , $ data ['line ' ], $ i );
95- }
96-
97- $ data ['executor ' ] = array_filter ($ data ['executor ' ]);
98-
99- // to make symfony exception more readable
100- if ($ data ['class ' ] == 'Symfony\Component\Debug\Exception\FatalErrorException ' ) {
101- preg_match ("~^(.+)' in ~ " , $ data ['exception ' ], $ matches );
102- if (isset ($ matches [1 ])) {
103- $ data ['exception ' ] = $ matches [1 ];
104- }
105- }
106-
107121 return $ data ;
108122 }
109123
0 commit comments