/** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $e * @return \Illuminate\Http\Response */ public function render($request, Exception $e) { $viewLog = new Logger('View Logs'); $viewLog->pushHandler(new StreamHandler(storage_path() . '/logs/laravel.log', Logger::INFO)); if ($e instanceof ModelNotFoundException) { Log::useFiles(storage_path() . '/logs/laravel.log'); $viewLog->addInfo('A 404 error (ModelNotFoundException) has been encountered, ' . 'details are as follows:\\n\\n' . $e->getMessage()); Log::error('A 404 error (ModelNotFoundException) has been encountered, ' . 'details are as follows:\\n\\n' . $e->getMessage()); abort(404); } if ($e instanceof ErrorException) { Log::useFiles(storage_path() . '/logs/laravel.log'); $viewLog->addInfo('A 500 error (ErrorException) has been encountered, ' . 'details are as follows:\\n\\n' . $e->getMessage()); Log::error('A 500 error (ErrorException) has been encountered, ' . 'details are as follows:\\n\\n' . $e->getMessage()); abort(500); } return parent::render($request, $e); }
<?php use Dingo\Api\Facade\API; use Illuminate\Support\Facades\Log; /* |-------------------------------------------------------------------------- | Application Error Logger |-------------------------------------------------------------------------- | | Here we will configure the error logger setup for the application which | is built on top of the wonderful Monolog library. By default we will | build a basic log file setup which creates a single file for logs. | */ Log::useFiles(storage_path() . '/logs/laravel.log'); /* |-------------------------------------------------------------------------- | Application Error Handler |-------------------------------------------------------------------------- | | Here you may handle any errors that occur in your application, including | logging them or displaying custom views for specific errors. You may | even register several error handlers to handle different types of | exceptions. If nothing is returned, the default error view is | shown, which includes a detailed stack trace during debug. | */ App::error(function (Exception $exception, $code) { Log::error($exception); }); API::error(function (\Illuminate\Database\Eloquent\ModelNotFoundException $exception) {
static function useFiles($path) { Log::useFiles($path); }