Laravel request and response logging

I am trying to catch the problem associated with a specific answer to laravel, so I use the after filter to record all activity, but I cannot figure out how to dump the request and response information to the log.

App::after( function ($request, $response) { Log::info('access.log', array('request' => $request->headers, 'response' => $response->headers)); } ); 

This code does not provide information about the status of the code for the answer that interests me the most.

Is there any way to see what comes out at the final stage of transferring information to a web server? Something like that?

 HTTP/1.1 200 OK Date: Tue, 25 Nov 2014 22:35:17 GMT Server: Apache/2.2.14 (Ubuntu) X-Powered-By: PHP/5.4.34-1+deb.sury.org~lucid+1 Cache-Control: no-cache, max-age=0 Expires: Tue, 25 Nov 2014 22:35:17 GMT Content-Type: application/json Via: 1.1 localhost:8080 Vary: Accept-Encoding Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Content-Length: 59 {"success":true,"result":{"min":5.7,"mean":9.7,"max":14.2}} 
+5
source share
3 answers

Until the status code finally returns in the headers, at this point you will not find it in the $ headers attribute. You can still get the status code by calling $ response-> getStatusCode ()

+1
source

Although this is an old post, I recently wanted to see all incoming requests and all outgoing responses in Laravel.

This package supports both laravel 5 and 5.1, so I assume you can use it as well.

For installation:

composer

Add prettus / laravel-request-logger to the β€œrequire” section of your composer.json file.

 "prettus/laravel-request-logger": "1.0.*" Run composer update to get the latest version of the package. 

or execute

 composer require prettus/laravel-request-logger 

right in your terminal

Laravel

In the config / app.php file, add "Prettus \ RequestLogger \ Providers \ LoggerServiceProvider" to the end of the providers array:

 'providers' => array( ..., 'Prettus\RequestLogger\Providers\LoggerServiceProvider', ), 

Post configuration

 php artisan vendor:publish --provider="Prettus\RequestLogger\Providers\LoggerServiceProvider" Configuration 

In your config/request-logger.php you can change the configuration for the log

 'logger' => [ 'enabled' => true, 'handlers' => ['Prettus\RequestLogger\Handler\HttpLoggerHandler'], 'file' => storage_path("logs/http.log"), 'level' => 'info', 'format' => 'common' ] 

<strong> Examples:

{method} {full-url}

[2015-04-03 00:00:00] local.INFO: GET http: //prettus.local/user/1? Param = lorem ["REQUEST"] {method} {full-url} {remote-addr} {port}

[2015-04-03 00:00:00] local.INFO: GET http: //prettus.local/user/1? Param = lorem 192.168.10.1 80 ["REQUEST"] {method} {root} {url} {full-url} {path} {decoded-path} {remote-addr} {format} {scheme} {port} {query string}

[2015-04-03 00:00:00] local.INFO: GET http: //prettus.local http: //prettus.local/user/1 http: //prettus.local/user/1? Param = lorem user / 1 user / 1 192.168.10.1 html http 80 param = lorem ["REQUEST"] [{status}] HTTP: {http-version} {content}

[2015-04-03 00:00:00] local.INFO: [200] HTTP: 1.1 {"id": 1, "name": "Anderson Andrade", "email": " contato@andersonandra.de "} [ "REACTION"]

+1
source

Along with a debug request / response to the log, you can try this service to get a good interface.

0
source

Source: https://habr.com/ru/post/1207700/


All Articles