jmarcher/laravel-request-logger
Composer 安装命令:
composer require jmarcher/laravel-request-logger
包简介
HTTP request logger middleware for Laravel
README 文档
README
Request and Response Logger for Laravel
Insiperd by Morgan - Node HTTP request logger
Installation
Composer
Add jmarcher/laravel-request-logger to the "require" section of your composer.json file.
"jmarcher/laravel-request-logger": "1.1.*"
Run composer update to get the latest version of the package.
or
Run composer require prettus/laravel-request-logger direct in your terminal
Laravel
In your config/app.php add 'Prettus\RequestLogger\Providers\LoggerServiceProvider' to the end of the providers array:
'providers' => [ Prettus\RequestLogger\Providers\LoggerServiceProvider::class, ]
Publish Configuration
php artisan vendor:publish --provider="Prettus\RequestLogger\Providers\LoggerServiceProvider"
Configuration
In your config/request-logger.php file, you can change configuration for logger
'logger' => [ 'enabled' => true, 'handlers' => ['Prettus\RequestLogger\Handler\HttpLoggerHandler'], 'file' => storage_path("logs/http.log"), 'level' => 'info', 'format' => 'common' ]
| Property | Type | Default Value | Description |
|---|---|---|---|
| enabled | boolean | true | Enable or disable log http |
| handlers | array | ['Prettus\RequestLogger\Handler\HttpLoggerHandler'] | Instance of the Monolog\Handler\HandlerInterface. (See more)[https://github.com/Seldaek/monolog#handlers] |
| file | string | storage_path("logs/http.log") | If you are using Prettus\RequestLogger\Handler\HttpLoggerHandler, you can set the file will be saved walk logs |
| level | string | info | Level logger write: [notice, info, debug, emergency, alert, critical, error, warning] |
| format | string | common | Format for the log record |
Format Interpolation
Variables
| Format | Description | Exemple |
|---|---|---|
| {method} | Get the request method. | PUT |
| {root} | Get the root URL for the application. | http://prettus.local |
| {url} | Get the URL (no query string) for the request. | http://prettus.local/users |
| {full-url} | Get the full URL for the request. | http://prettus.local/users?search=lorem |
| {path} | Get the current path info for the request. | /users |
| {decoded-path} | Get the current encoded path info for the request. | /users |
| {remote-addr} | Returns the client IP address. | 192.168.10.1 |
| {format} | Gets the format associated with the mime type. | html |
| {scheme} | Gets the request's scheme. | http |
| {port} | Returns the port on which the request is made. | 80 |
| {query-string} | Generates the normalized query string for the Request. | ?search=lorem |
| {remote-user} | Returns the user. | |
| {referer} | The page address (if any) by which the user agent to the current page | |
| {user-agent} | Get user agent | Mozilla/5.0 (Windows NT 6.3; WOW64) |
| {date} | Current Date | 2015-04-05 14:00:00 |
| {request-content} | Get the request content if it exists. | {json:response} |
| {content} | Get the response content. | {json:response} |
| {content-length} | Get the content length in bytes | 4863 |
| {response-time} | Response time in ms | 231 |
| {status} | Http status code | 200 |
| {http-version} | Http protocol version | 1.1 |
| {server[KEY]} | $_SERVER Server and execution environment information (See more)[http://php.net/manual/reserved.variables.server.php] | |
| {req[HEADER]} | Request Header values | |
| {res[HEADER]} | Response Header values |
Default formats
| Name | Format |
|---|---|
| combined | {remote-addr} - {remote-user} [{date}] "{method} {url} HTTP/{http-version}" {status} {content-length} "{referer}" "{user-agent}" |
| common | {remote-addr} - {remote-user} [{date}] "{method} {url} HTTP/{http-version}" {status} {content-length} |
| dev | {method} {url} {status} {response-time} ms - {content-length} |
| short | {remote-addr} {remote-user} {method} {url} HTTP/{http-version} {status} {content-length} - {response-time} ms |
| tiny | {method} {url} {status} {content-length} - {response-time} ms |
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"} ["RESPONSE"]
jmarcher/laravel-request-logger 适用场景与选型建议
jmarcher/laravel-request-logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.2k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2016 年 04 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「logger」 「response」 「request」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jmarcher/laravel-request-logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jmarcher/laravel-request-logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jmarcher/laravel-request-logger 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Workflow logger
High-performance, zero-dependency PSR-3 logger for MonkeysLegion with structured logging, handlers, processors, and PHP 8.4 features.
Class to generate a standard structure for api json responses
Adds request-parameter validation to the SLIM 3.x PHP framework
Logging http requests and errors
Logger classes (currently supports file system, console and simple email logging), part of QuEasy PHP Framework
统计信息
- 总下载量: 5.2k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-04-27