Laravel custom error pages and error log handling

Source: Internet
Author: User
Laravel framework usually comes with an error page, if the configuration file Debug=true, will expand the error debugging interface, through the stack tracking can be detailed to see the program's execution process, and error prompts and can accurately locate the error line, debugging is very convenient. In a production environment to turn off Debug=false, the error response displays a simple error page; The problem is that a custom error is needed in the actual project and the administrator can see the error log exactly:

Laravel Easy to handle!

Custom error:

It is also convenient if you want to customize a global error page: An error handler is defined in the app/global.php file in the root directory:

App::error (function (Exception $exception, $code) {log::error ($exception);    return Response::make (' server seems to have a bit of a problem oh! ', 404);});

This function is automatically called when an exception or error is encountered, and the error log is logged, and the front end is given a 404 content prompt response.

Here the response content can be arbitrary, it is best to specify to the error page, you can also specify to the custom controller, or directly output custom error prompt!

App::error (function (Exception $exception, $code) {log::error ($exception);    Return Response::view (' error ', 404);});

Say the error log; Laravel use of the famous monolog, log records when the log file is cut into multiple files, preferably in days to generate, easy to check the wrong, specify the error log path

Log:: Usefiles (Storage_path (). '/logs/laravel.log ' );

The above describes the Laravel custom error page and error log processing, including the aspects of the content, I hope to be interested in PHP tutorial friends helpful.

  • Related Article

    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.