app/Http/Kernel.php
namespace App\Http; use Illuminate\Foundation\Http\Kernel as HttpKernel; use App\Http\Middleware\UA\SetLocale; use App\Http\Middleware\UA\ResponseJsonFormatter; class Kernel extends HttpKernel { /** * The application's global HTTP middleware stack. * * These middleware are run during every request to your application. * * @var array */ protected $middleware = [ ・・・ + \App\Http\Middleware\RequestLogger::class, ];
app/Http/Middleware/RequestLogger.php
namespace App\Http\Middleware; use Closure; class RequestLogger { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (env('DEBUG_REQUEST', false)) { $this->_writeLog($request); } return $next($request); } private function _writeLog($request): void { \Log::channel('request')->debug( $request->method() . " : " . json_encode( ['url' => $request->fullUrl(), 'request' => $request->all(), 'header' => $request->headers->all()], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ) ); } }
.env
DEBUG_REQUEST=true
$ php artisan config:clear