https://github.com/patrickriemer/http-log
Simple request logging package
https://github.com/patrickriemer/http-log
http logging middleware
Last synced: 21 days ago
JSON representation
Simple request logging package
- Host: GitHub
- URL: https://github.com/patrickriemer/http-log
- Owner: patrickriemer
- License: apache-2.0
- Created: 2023-01-09T08:23:27.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-12T03:29:08.000Z (over 2 years ago)
- Last Synced: 2025-11-18T05:36:00.304Z (3 months ago)
- Topics: http, logging, middleware
- Language: PHP
- Homepage:
- Size: 31.3 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# HTTP log
Offers a middleware to automatically log HTTP requests and responses for API endpoints. A model allows manually logging as well. All data will be logged into the database table "http_logs". The following information will be captured:
* Unique request ID (UUID 4)
* Request method
* Request path
* Request URI
* Request header
* Request IP
* Request input (JSON)
* Response status code
* Response header
* Response content (JSON)
* Turnaround time in milliseconds (based on PHP's hrtime, rounded up to the next millisecond)
To enable the request logging for all API requests, add it to the api middleware group in the App\Http\Kernel.php:
```phpregexp
use PatrickRiemer\HttpLog\Http\Middleware\LogRequestResponse;
protected $middlewareGroups = [
'api' => [
LogRequestResponse::class,
],
];
```
The logging is deactivated per default since version 1.1.0. You can enable it in your .env file with the following snippet:
```shell
HTTP_LOG_ENABLED=true
```
The middleware will log the request IP. If you are sitting behind Cloudflare or a similar service that forwards the real IP address, you can specify the header attribute in the environment file that should be used for logging. Example for Cloudflare:
```shell
HEADER_REAL_IP=x-real-ip
```