@@ -125,22 +125,31 @@ public function exceptionHandler(Throwable $exception)
125125 [$ statusCode , $ exitCode ] = $ this ->determineCodes ($ exception );
126126
127127 if ($ this ->config ->log === true && ! in_array ($ statusCode , $ this ->config ->ignoreCodes , true )) {
128- log_message ('critical ' , " {message} \nin {exFile} on line {exLine}. \n{trace} " , [
128+ log_message ('critical ' , get_class ( $ exception ) . " : {message} \nin {exFile} on line {exLine}. \n{trace} " , [
129129 'message ' => $ exception ->getMessage (),
130130 'exFile ' => clean_path ($ exception ->getFile ()), // {file} refers to THIS file
131131 'exLine ' => $ exception ->getLine (), // {line} refers to THIS line
132132 'trace ' => self ::renderBacktrace ($ exception ->getTrace ()),
133133 ]);
134+
135+ // Get the first exception.
136+ $ last = $ exception ;
137+
138+ while ($ prevException = $ last ->getPrevious ()) {
139+ $ last = $ prevException ;
140+
141+ log_message ('critical ' , '[Caused by] ' . get_class ($ prevException ) . ": {message} \nin {exFile} on line {exLine}. \n{trace} " , [
142+ 'message ' => $ prevException ->getMessage (),
143+ 'exFile ' => clean_path ($ prevException ->getFile ()), // {file} refers to THIS file
144+ 'exLine ' => $ prevException ->getLine (), // {line} refers to THIS line
145+ 'trace ' => self ::renderBacktrace ($ prevException ->getTrace ()),
146+ ]);
147+ }
134148 }
135149
136150 $ this ->request = Services::request ();
137151 $ this ->response = Services::response ();
138152
139- // Get the first exception.
140- while ($ prevException = $ exception ->getPrevious ()) {
141- $ exception = $ prevException ;
142- }
143-
144153 if (method_exists ($ this ->config , 'handler ' )) {
145154 // Use new ExceptionHandler
146155 $ handler = $ this ->config ->handler ($ statusCode , $ exception );
@@ -325,7 +334,14 @@ protected function render(Throwable $exception, int $statusCode)
325334 */
326335 protected function collectVars (Throwable $ exception , int $ statusCode ): array
327336 {
328- $ trace = $ exception ->getTrace ();
337+ // Get the first exception.
338+ $ firstException = $ exception ;
339+
340+ while ($ prevException = $ firstException ->getPrevious ()) {
341+ $ firstException = $ prevException ;
342+ }
343+
344+ $ trace = $ firstException ->getTrace ();
329345
330346 if ($ this ->config ->sensitiveDataInTrace !== []) {
331347 $ trace = $ this ->maskSensitiveData ($ trace , $ this ->config ->sensitiveDataInTrace );
0 commit comments