laravelÏÔʾ¹ýʧÐÅÏ¢
laravelÊÇÒ»¸öÊ¢ÐеÄphp web¿ò¼Ü£¬ËüÌṩÁËÐí¶àÀû±ãµÄ¹¦Ð§À´¼ò»¯web¿ª·¢¡£È»¶ø£¬ÏñÈκÎÆäËûÓ¦ÓóÌÐòÒ»Ñù£¬laravelÒ²¿ÉÄ᷺ܻÆð¹ýʧ¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÌÖÂÛÔõÑùÔÚlaravelÖÐÏÔʾ¹ýʧÐÅÏ¢£¬ÒÔ±ã¸üºÃµØÃ÷È·Ï¢Õù¾öÎÊÌâ¡£
LaravelÌṩÁËÐí¶à¿ÉÓÃÓÚµ÷ÊԵŤ¾ßºÍÊÖÒÕ£¬°üÀ¨²î±ð¼¶±ðµÄÈÕÖ¾¼Í¼¡¢µ÷ÊÔÌõ¡¢¹ýʧ¸ú×ٵȡ£ÕâЩ¹¦Ð§¶¼ÊÇΪÁËÉÁ¿ª·¢Ö°Ô±Ô½·¢ÇáËɵØÕï¶ÏLaravelÓ¦ÓóÌÐòÖеÄÈκÎÎÊÌâ¡£ÔÚ´ËÀú³ÌÖУ¬×îÖ÷ÒªµÄÊÇÄܹ»²¶»ñºÍÏÔʾ¹ýʧÐÂÎÅ¡£ÔÚLaravelÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÒªÁìÀ´ÏÔʾ¹ýʧÐÂÎÅ£º
ʹÓÃLaravelµÄÈÕÖ¾¼Í¼¹¦Ð§
LaravelµÄÈÕÖ¾¼Í¼¹¦Ð§ÊÇÒ»¸öºÜÊÇÇ¿Ê¢µÄ¹¤¾ß£¬¿ÉÒÔ²¶»ñÖÖÖÖÀàÐ͵ĹýʧÐÂÎÅ¡£ËüÔÊÐíÄú¼Í¼ӦÓóÌÐòµÄÐí¶à²î±ð²¿·ÖµÄÐÅÏ¢£¬²¢½«Æä´æ´¢ÔÚ¿ÉÉèÖõÄÈÕÖ¾ÎļþÖС£Ä¬ÈÏÇéÐÎÏ£¬LaravelʹÓÃMonolog¿âÀ´¼Í¼ÈÕÖ¾£¬¿ÉÊÇÄú¿ÉÒÔËæʱ¸ü¸ÄÕâ¸öÐÐΪ¡£
ΪÁ˼ͼһ¸ö¹ýʧ£¬Äú¿ÉÒÔʹÓÃLogÃÅÃæµÄһϵÁÐÒªÁ죬Èçlog()£¬debug()£¬info()£¬warning()ºÍerror()ÒªÁì¡£ÈôÊÇÄúÒª¼Í¼һ¸ö¹ýʧ£¬Äú¿ÉÒÔʹÓÃerror()ÒªÁì¡£Ëü½«ÔÚÈÕÖ¾ÎļþÖн¨ÉèÒ»¸ö¹ýʧ¼¶±ðµÄÈÕÖ¾ÌõÄ¿£¬²¢°üÀ¨Óйعýʧ±¬·¢µÄÏêϸÐÅÏ¢¡£
ÀýÈ磬ÒÔÏ´úÂ뽫¼Í¼һ¸ö¹ýʧÐÂÎŲ¢½«ÆäÌí¼Óµ½ÈÕÖ¾ÎļþÖУº
use IlluminateSupportFacadesLog; ... try { // some code } catch (Exception $e) { Log::error('Error message: '.$e->getMessage().', Error code: '.$e->getCode()); }
µÇ¼ºó¸´ÖÆ
Õ⽫ÔÚÈÕÖ¾ÎļþÖÐÌí¼ÓÒ»¸ö¹ýʧ¼¶±ðµÄÈÕÖ¾ÌõÄ¿£¬ÆäÖаüÀ¨Óйز¶»ñµ½µÄÒì³£µÄÏêϸÐÅÏ¢¡£ÕâÊǺÜÊÇÓÐÓõģ¬ÓÉÓÚËü¿ÉÒÔÈÃÄãÏàʶÎÊÌâµÄ½¹µãÊÇʲô£¬Ó¦¸ÃÔÚÄÇÀï×ÅÊÖ½â¾öÎÊÌâ¡£
ʹÓÃPHPµÄerror_reporting()º¯Êý
PHPÌṩÁËÒ»¸öÄÚÖùýʧ´¦ÀíÆ÷£¬¿ÉÒÔ´¦ÀíÔËÐÐʱ¹ýʧºÍÖÒÑÔ¡£ÔÚLaravelÓ¦ÓóÌÐòÖУ¬¿ÉÒÔʹÓÃPHPµÄerror_reporting()º¯ÊýÀ´¿ØÖÆÄÄЩ¹ýʧӦ¸ÃÏÔʾÔÚÆÁÄ»ÉÏ¡£
ÔõÑùʹÓÃerror_reporting()º¯Êý£º
¶ÔÕû¸öÓ¦ÓóÌÐòÉèÖùýʧ¼¶±ð
// set error reporting level to E_ALL error_reporting(E_ALL); // or, hide all errors error_reporting(0);
µÇ¼ºó¸´ÖÆ
¶Ôij¸öÖ¸¶¨´úÂë¿éÉèÖùýʧ¼¶±ð
// set error reporting level to E_ALL error_reporting(E_ALL); // some code // set error reporting level to 0 error_reporting(0); // some other code
µÇ¼ºó¸´ÖÆ
ÔÚÕâÀÄã¿ÉÒÔ¿´µ½ÔõÑùʹÓÃerror_reporting()º¯Êý¿ØÖÆÄÄЩ¼¶±ðµÄ¹ýʧӦ¸ÃÏÔʾÔÚÆÁÄ»ÉÏ¡£ÈôÊÇÄú½«¹ýʧ¼¶±ðÉèÖÃΪE_ALL£¬½«»áÏÔʾËùÓйýʧ£¬Õâ¹ØÓÚµ÷ÊÔÓ¦ÓóÌÐòÌØÊâÓÐÓá£ÈôÊÇÄúÏëÔÚÕýʽÇéÐÎÖнûÓùýʧÐÂÎÅ£¬Ôò¿ÉÒÔ½«¹ýʧ¼¶±ðÉèÖÃΪ0¡£
ʹÓÃ×Ô½ç˵¹ýʧ´¦Àí³ÌÐò
Äú¿ÉÒÔʹÓÃLaravelµÄException HandlerÀ´²¶»ñºÍ´¦ÀíÔËÐÐʱÒì³£¡£ÔÚLaravelÖУ¬Ä¬ÈÏÇéÐÎÏ£¬ËùÓÐÒì³£¶¼±»×ª´ïµ½AppExceptionsHandlerÀàÖоÙÐд¦Àí¡£Äú¿ÉÒÔʹÓøÃÀàÖеÄrender()ÒªÁìÀ´×Ô½ç˵¹ýʧ´¦Àí³ÌÐò£¬²¢½«¹ýʧÐÂÎÅÏÔʾÔÚÆÁÄ»ÉÏ¡£
ÀýÈ磬ÒÔÏ´úÂ뽫´ÓHandlerÀàÖⶻñÒì³££¬²¢½«Òì³£ÐÂÎÅÏÔʾÔÚÆÁÄ»ÉÏ£º
public function render($request, Exception $exception) { if($exception instanceof CustomException) { return response()->view('errors.custom', [], 500); } return parent::render($request, $exception); }
µÇ¼ºó¸´ÖÆ
ÔÚÕâÀÎÒÃÇ´¦ÀíÁËÒ»¸öÃûΪCustomExceptionµÄÒì³££¬²¢Í¨¹ýresponse()ʵÀý»¯¹¤¾ß½«¹ýʧÐÂÎÅÊä³öµ½×Ô½ç˵ÊÓͼÖС£
ÔÚ¿ª·¢Ä£Ê½ÏÂʹÓÃLaravelµÄµ÷ÊÔÌõ
LaravelÌṩÁËÒ»¸öºÜÊÇÓÐÓõĵ÷ÊÔÌõ£¬Ëü¿ÉÒÔ×ÊÖúÄú¿ìËÙ¸ú×ÙÓ¦ÓóÌÐòÖеÄÎÊÌâ¡£ÔÚ¿ª·¢Ä£Ê½Ï£¬µ÷ÊÔÌõ½«×Ô¶¯·ºÆðÔÚÒ³Ã涥²¿£¬ÆäÖаüÀ¨ÓйØÄ¿½ñÒ³ÃæµÄÖÖÖÖÐÅÏ¢£¬ÀýÈçÖ´ÐÐʱ¼ä¡¢SQLÅÌÎÊ¡¢Òì³£¡¢ÖÒÑÔ¡¢ÈÕÖ¾ºÍ¸ü¶à¡£
ÒªÆôÓõ÷ÊÔÌõ£¬ÄúÐèÒª½«APP_DEBUGÇéÐαäÁ¿ÉèÖÃΪtrue£¬²¢ÔÚä¯ÀÀÆ÷Öз¿ªLaravelÓ¦ÓóÌÐò¡£Ò»µ©¿ªÆô£¬µ÷ÊÔÌõ½«Ê¼ÖÕÔÚÒ³Ã涥²¿ÏÔʾ£¬Ö±µ½Äú½«Æä¹Ø±Õ»ò½«ÇéÐαäÁ¿ÉèÖÃΪfalseΪֹ¡£
×ܽá
LaravelÌṩÁËÐí¶àÓÐÓõŤ¾ßºÍÊÖÒÕÀ´²¶»ñºÍÏÔʾ¹ýʧÐÂÎÅ¡£Ê¹ÓÃÕâЩҪÁ죬¿ª·¢Ö°Ô±¿ÉÒÔÇáËɵص÷ÊÔLaravelÓ¦ÓóÌÐòÖеÄÖÖÖÖÎÊÌ⣬ÀýÈçÔËÐÐʱ¹ýʧ¡¢Êý¾Ý¿âÅþÁ¬ÎÊÌâµÈ¡£ÏàʶÔõÑùÔÚLaravelÖÐÏÔʾ¹ýʧÐÂÎÅÊdzÉΪһ¸öÓÅÒìWeb¿ª·¢Ö°Ô±µÄ±Ø±¸ÊÖÒÕÖ®Ò»¡£
ÒÔÉϾÍÊÇlaravelÏÔʾ¹ýʧÐÅÏ¢µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡