Download the PHP package san4io/request-logger without Composer
On this page you can find all versions of the php package san4io/request-logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package request-logger
Request Logger
Package for logging Laravel HTTP requests. By default it uses Monolog with LogStash formatter, but it can be overriden in your ServiceProvider, check Advanced Configuration section.
Installation
You can install the package via composer:
You can publish config
Configuration
In request-logger.php
config file you'll find current properties:
Property | Default | Descirption |
---|---|---|
storage_path | /logs/request-logger.log | Where your logs gonna be stored |
param_exceptions | ['password', 'password_confirmation'] | which params should be filtered out from RequestParamsFormatter |
Usage
In global middleware:
In group of routes:
In single route:
Default Log Context Formatters
Formatter | Name | Descirption | Example |
---|---|---|---|
RequestIPFormatter | request_ip | Returns request ip information | 192.22.22.11 |
RequestMethodFormatter | request_method | Returns request method information | POST |
RequestUriFormatter | request_uri | Returns request uri information | http://localhost/api/v1/authenticate |
RequestHeadersFormatter | request_headers | Returns request headers information | {cookie:[Phpstorm-f176c91a=b5df2557-0cd3-44be-857d-7ea59b93c24a; io=Xm-fflHJzYnRSle0AAAB; JSESSIONID.41a4f06a=ux60gwkijzfr1cleylxjci7po;], "origin":["http://localhost"], "accept":["application/json"]} |
RequestParamsFormatter | request_params | Returns request params(filtered) information | {"email":"qwe"} |
ResponseBenchmarkFormatter | response_ms | Returns execution time | 0.1858180046081543 |
ResponseContentFormatter | response_content | Return response content(can be very heavy, use wisely) | {\"message\":\"The given data was invalid.\",\"errors\":{\"email\":[\"The email must be a valid email address.\"]}} |
Extending
You can extend your Logger with your own ContextFormatters.
Your context formatter should extend \San4io\RequestLogger\Contracts\ContextFormatterContract
interface.
In format
method should return your desired output.
In name
method, you should return unique name of formatter
Advanced Configuration
Overriding Logger
You can override logger in your ServiceProvider by binding your logger to 'app.request.logger'
For example you want other Formatter like MongoDBFormatter.
That's it, you have setted logger with your desired formatter.
Or you can create your own logger with different name, and inject it to RequestLogger
for example:
Overriding LogContextFormatter
It is possible that you need some addidtional data to be returned to your log. In this case you extend \San4io\RequestLogger\Contracts\ContextFormatterContract
interface (check Extending section) and adding it to LogContextFormatter. Example:
Road map
- Tests
Contribution
Any contributions welcome!