我使用下面的代码来记录我的 API 的每个请求和响应,但现在它不适用于 Laravel 5.2。
我曾尝试使用https://laravel.com/docs/5.2/middleware#terminable-middleware但没有成功。
use Closure;
use Illuminate\Contracts\Routing\TerminableMiddleware;
use Illuminate\Support\Facades\Log;
class LogAfterRequest implements TerminableMiddleware {
public function handle($request, Closure $next)
{
return $next($request);
}
public function terminate($request, $response)
{
$logFile = 'log.txt';
Log::useDailyFiles(storage_path().'/logs/'.$logFile);
Log::info('app.requests', ['request' => $request->all(), 'response' => $response->getContent()]);
}
}
谁能建议我解决方案?