Laravel custom error page and error log processing

Source: Internet
Author: User
: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.