gpt4 book ai didi

php - 如何将附加数据发送到 laravel.log 文件?

转载 作者:行者123 更新时间:2023-12-02 04:16:07 30 4
gpt4 key购买 nike

我在 laravel.log 文件中收到一些错误消息,但错误描述并不能帮助我找到问题。我想在报告给日志文件的所有错误中注册一些额外的数据,具体来说,请求 URL请求数据。我怎样才能添加这两件事?

[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}

最佳答案

/app/Exceptions/Handler.php中修改public函数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}

关于php - 如何将附加数据发送到 laravel.log 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33666498/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com