我在laravel.log文件中收到了一些错误消息,但错误说明并没有帮助我找到问题。我想在报告给日志文件的所有错误中注册一些额外的数据,具体而言,request URL
和request data
。我怎样才能添加这两件事?
[2015-11-09 13:30:01] production.ERROR: exception 'Illuminate\Session\TokenMismatchException' in /bootstrap/cache/compiled.php:2888
Stack trace:
#0 [internal function]: Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#1 /bootstrap/cache/compiled.php(9464): call_user_func_array(Array, Array)
#2 /app/Http/Middleware/CheckForMaintenanceMode.php(39): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#3 [internal function]: App\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#4 /bootstrap/cache/compiled.php(9464): call_user_func_array(Array, Array)
#5 /bootstrap/cache/compiled.php(12789): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#6 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#7 /bootstrap/cache/compiled.php(9464): call_user_func_array(Array, Array)
#8 /bootstrap/cache/compiled.php(11412): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#9 [internal function]: Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#10 /bootstrap/cache/compiled.php(9464): call_user_func_array(Array, Array)
#11 /bootstrap/cache/compiled.php(12530): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#12 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#13 /bootstrap/cache/compiled.php(9464): call_user_func_array(Array, Array)
#14 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#15 /bootstrap/cache/compiled.php(9454): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#16 /bootstrap/cache/compiled.php(2209): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#17 /bootstrap/cache/compiled.php(2192): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#18 /public/index.php(54): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#19 {main}
答案 0 :(得分:4)
在/app/Exceptions/Handler.php
修改public function report(Exception $e)
。
// ...
use Request;
// ...
public function report(Exception $e)
{
if ($this->shouldReport($e)) {
$request = Request::all();
$this->log->error("request url: " . Request::url());
$this->log->error("request data: " . json_encode($request));
}
parent::report($e);
}
最后,laravel.log中报告的错误将包含请求URL和数据。
[2015-11-12 03:41:14] local.ERROR: request url: http://example.com/path
[2015-11-12 03:41:14] local.ERROR: request data: {"key":"value"}
[2015-11-12 03:41:14] local.ERROR: exception 'Illuminate\Session\TokenMismatchException' in /bootstrap/cache/compiled.php:2888
Stack trace:
#0 [internal function]: Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#1 /bootstrap/cache/compiled.php(9464): call_user_func_array(Array, Array)
#2 /app/Http/Middleware/CheckForMaintenanceMode.php(39): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#3 [internal function]: App\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#4 /bootstrap/cache/compiled.php(9464): call_user_func_array(Array, Array)
#5 /bootstrap/cache/compiled.php(12789): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#6 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#7 /bootstrap/cache/compiled.php(9464): call_user_func_array(Array, Array)
#8 /bootstrap/cache/compiled.php(11412): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#9 [internal function]: Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#10 /bootstrap/cache/compiled.php(9464): call_user_func_array(Array, Array)
#11 /bootstrap/cache/compiled.php(12530): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#12 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#13 /bootstrap/cache/compiled.php(9464): call_user_func_array(Array, Array)
#14 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#15 /bootstrap/cache/compiled.php(9454): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#16 /bootstrap/cache/compiled.php(2209): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#17 /bootstrap/cache/compiled.php(2192): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#18 /public/index.php(54): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#19 {main}
答案 1 :(得分:0)
很明显,您有TokenMismatchException
我该如何解决?
您可以通过发送由Laravel生成的_token
来修复它。
如果使用表单助手,您可以在表单中默认获得_token
,如果不是,您可以通过将其作为隐藏传递手动执行
<input type="hidden" name="_token" value="{{ csrf_token() }}">
注意:
默认情况下,Laravel会将所有错误记录在storage / logs / laravel-date.log中的.log文件中。
如果要记录这些日志,则需要在db中手动捕获并记录。