refactoring error handling.

This commit is contained in:
Taylor Otwell
2011-11-10 22:46:01 -06:00
parent 0dc43490a6
commit 0a2c61ec29
4 changed files with 99 additions and 136 deletions

View File

@@ -36,29 +36,22 @@ return array(
| Error Handler
|--------------------------------------------------------------------------
|
| Because of the various ways of managing error logging, you get complete
| flexibility in Laravel to manage all error logging as you see fit.
| Because of the various ways of managing errors, you get complete freedom
| to manage errors as you desire. Any error that occurs in your application
| will be sent to this Closure.
|
| This function will be called when an error occurs in your application.
| You are free to handle the exception any way you want. The severity
| will be a human-readable severity level such as "Parsing Error".
| By default, when error detail is disabled, a generic error page will be
| rendered by the handler. After this handler is complete, the framework
| will stop processing the request and "exit" will be called.
|
*/
'handler' => function($exception, $severity, $message, $config)
'handler' => function($exception, $config)
{
if ($config['detail'])
if ( ! $config['detail'])
{
$data = compact('exception', 'severity', 'message');
$response = Response::view('error.exception', $data)->status(500);
Response::error('500')->send();
}
else
{
$response = Response::error('500');
}
$response->send();
},
/*
@@ -71,15 +64,18 @@ return array(
| be called anytime an error occurs within your application and error
| logging is enabled.
|
| You may log the error message however you like; however, a simple logging
| solution has been setup for you which will log all error messages to a
| single text file within the application storage directory.
| You may log the error message however you like; however, a simple log
| solution has been setup for you which will log all error messages to
| a single text file within the application storage directory.
|
| Of course, you are free to implement more complex solutions including
| e-mailing the exceptions details to your team, etc.
|
*/
'logger' => function($exception, $severity, $message, $config)
'logger' => function($exception, $config)
{
$message = date('Y-m-d H:i:s').' '.$severity.' - '.$message.PHP_EOL;
$message = date('Y-m-d H:i:s').' - '.$exception->getMessage().PHP_EOL;
File::append(STORAGE_PATH.'log.txt', $message);
}