Home >Backend Development >PHP Tutorial >laravel custom error page and error log processing

laravel custom error page and error log processing

WBOY
WBOYOriginal
2016-08-08 09:30:081432browse

The laravel framework generally comes with an error page. If debug=true is set in the configuration file, the error debugging interface will be expanded. Through the stack trace, you can see the execution flow of the program in detail, as well as error prompts and the error line can be accurately located for debugging. Very convenient to get up. In the production environment, debug=false must be turned off. At this time, the error response will display a simple error page; here comes the problem, custom errors need to be used in actual projects, and the administrator can accurately see the error log:

laravel can easily do it!

Customized error:

It is also very convenient if you want to customize a global error page: define an error handling function in the app/global.php file in the root directory:

App::error(function(Exception $exception, $code)
{
	Log::error($exception);
    return Response::make('服务器好像出了点问题哦!',404);
});

When an exception or error is encountered here, it will Automatically call this function; record the error log, and give the front end a 404 prompt response with content;

The response content here can be arbitrary, it is best to specify it to the error page, or you can specify it to a custom controller, or directly output it automatically Define error message!

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

Let’s talk about the error log; laravel uses the famous monolog. When logging, the log file is cut into multiple files. It is best to generate them in days to facilitate error checking and specify the error log. Path

<span>Log::</span><span><em>useFiles</em></span><span>(storage_path().</span><span>'/logs/laravel.log'</span><span>);</span>

The above introduces laravel's custom error page and error log processing, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn