: This article mainly introduces laravel custom error pages and error log processing. For more information about PHP tutorials, see. The laravel framework usually comes with an error page. if debug is set to true in the configuration file, the error debugging interface is displayed. the execution process of the program can be detailed through stack tracing, and error prompts and can accurately locate the error line, debugging is very convenient. To disable debug = false in the production environment, a simple error page is displayed in the error response. The problem arises. you need to use custom errors in the actual project. the administrator can see the error log accurately:
Laravel is easy to handle!
Custom error:
If you want to customize a global error page, you can easily define an error handler in the app/global. php file in the root directory:
App: error (function (Exception $ exception, $ code) {Log: error ($ exception); return Response: make ('The server seems to have encountered a problem! ', 404 );});
In this case, when an exception or error occurs, this function is automatically called. the error log is recorded and a 404 response message is sent to the front-end;
The response content can be customized here. it is best to specify the error page or custom controller, or directly output the custom error prompt!
App: error (function (Exception $ exception, $ code) {Log: error ($ exception); return Response: view ('error', 404 );});
Let's talk about error logs. laravel uses the famous monolog. when logging, it is best to cut the log file into multiple files. it is best to generate the log file in days to facilitate error detection and specify the error log path.
Log ::UseFiles(Storage_path (). '/logs/laravel. log ');
The above introduces laravel custom error pages and error log processing, including some content, and hope to be helpful to friends who are interested in PHP tutorials.