codetech/laravel-api-logs
Composer 安装命令:
composer require codetech/laravel-api-logs
包简介
A lightweight Laravel package for logging requests made to your API.
README 文档
README
Laravel API Requests Logger
A lightweight Laravel package for logging requests made to your API.
Requirements
| Package version | Laravel | PHP | Status |
|---|---|---|---|
| 3.x (this branch) | 11 / 12 / 13 | ≥ 8.2 | Active |
2.x (v2) |
7 – 10 | ≥ 7.2 | Security fixes |
1.x (v1) |
7 – 10 | ≥ 7.2 | End of life |
Upgrading from an older version? See the upgrade guide.
Installation
Add the package to your Laravel application using composer:
composer require codetech/laravel-api-logs
The service provider is registered automatically via package discovery.
Migrations
Publish the migration file:
php artisan vendor:publish --provider="CodeTech\ApiLogs\Providers\ApiLogServiceProvider" --tag=migrations
Run the migration:
php artisan migrate
Usage
Add the HasApiLogs trait to the model that makes the requests (typically your User model):
use CodeTech\ApiLogs\Traits\HasApiLogs; class User extends Authenticatable { use HasApiLogs; }
To start logging requests made to your API, append the middleware to the api middleware group in your bootstrap/app.php:
use CodeTech\ApiLogs\Http\Middleware\LogApiRequest; use Illuminate\Foundation\Configuration\Middleware; return Application::configure(basePath: dirname(__DIR__)) // ... ->withMiddleware(function (Middleware $middleware) { $middleware->appendToGroup('api', LogApiRequest::class); }) // ... ->create();
Only authenticated requests are logged. Each log stores the URL, HTTP method, client IP, request data, request headers, response data and the request duration, and is linked to the authenticated user through a polymorphic causer relation:
$user->apiLogs; // all ApiLog entries for the user $apiLog->causer; // the model that made the request
Configuration
Sensitive values are redacted by default before a log is stored: common credential fields (password, token, access_token, …) in the request data, query string and response data, and sensitive request headers (Authorization, Cookie, X-Api-Key, …) are replaced with [REDACTED].
To customize the authentication guard, the redaction lists or the replacement string, publish the config file:
php artisan vendor:publish --provider="CodeTech\ApiLogs\Providers\ApiLogServiceProvider" --tag=config
Then adjust config/api-logs.php:
return [ 'guard' => null, 'redact' => [ 'replacement' => '[REDACTED]', 'keys' => ['password', 'access_token' /* , ... */], 'headers' => ['authorization', 'cookie' /* , ... */], ], ];
guard pins the authentication guard used to resolve the user a logged request is attributed to (e.g. 'sanctum'). When null, the request's default guard is used — the one set by the auth middleware, or the application's default guard.
keys are matched case-insensitively and recursively against the request payload, query string and response data; headers are matched against request header names.
Testing & code quality
The test suite is split into Unit and Feature suites. Run the tests, static analysis and code-style checks via Composer:
composer test # PHPUnit test suite composer analyse # PHPStan/Larastan static analysis composer lint # Pint code-style check (run `composer format` to fix)
Changelog
Every release is documented on the GitHub releases page.
Contributing
Contributions are welcome! Please read the contributing guidelines before opening an issue or pull request.
Security
If you discover a security vulnerability, please follow the security policy — do not report it publicly.
Support
If this package helps you, consider starring the repository — it helps other developers discover it.
License
codetech/laravel-api-logs is open-sourced software licensed under the MIT license.
About CodeTech
CodeTech is a web development agency based in Matosinhos, Portugal. Oh, and we LOVE Laravel!
codetech/laravel-api-logs 适用场景与选型建议
codetech/laravel-api-logs 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 858 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 05 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「laravel」 「logs」 「laravel-package」 「codetech」 「laravel-api-logs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 codetech/laravel-api-logs 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 codetech/laravel-api-logs 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 codetech/laravel-api-logs 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The tenancy/tenancy logs mutations
A PSR-7 compatible library for making CRUD API endpoints
Laravel 5.x.x library for integration Monolog Sentry
Pacote simplificado para persistência de logs
Change logs for orchid platform.
A beautiful, zero-dependency UI for querying and viewing AWS CloudWatch logs directly inside your Laravel application.
统计信息
- 总下载量: 858
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-05-03
