memran/marwa-logger
Composer 安装命令:
composer require memran/marwa-logger
包简介
Lightweight PSR-3 JSON logger for PHP with redaction, rotation, and retention.
README 文档
README
Lightweight PSR-3 JSON logger for PHP 8.1+ with sensitive-data redaction, file rotation, and retention cleanup.
Features
- ✅ PSR-3 compatible
SimpleLogger - 🧾 NDJSON output for easy ingestion by log processors
- 🔒 Recursive sensitive-data filtering
- 🚦 Production gating by log level and request origin
- 🗂️ File rotation by size
- ♻️ Optional retention by age and file count
- 🧪 Composer scripts, PHPUnit, PHPStan, and CI included
📦 Installation
composer require memran/marwa-logger
🚀 Quick Start
<?php require __DIR__ . '/vendor/autoload.php'; use Marwa\Logger\Logger; $logger = Logger::boot( channel: 'payments', env: 'prod', path: __DIR__ . '/storage/logs', size: '10MB', ); $logger->info('checkout_started', ['user_id' => 42]); $logger->error('payment_failed', ['_origin' => 'system', 'order_id' => 991]);
Logger::boot() defaults to APP_ENV and storage/logs when env and path are omitted.
⚙️ Advanced File Sink Configuration
Use StorageFactory when you need retention controls:
use Marwa\Logger\SimpleLogger; use Marwa\Logger\Storage\StorageFactory; use Marwa\Logger\Support\SensitiveDataFilter; use Psr\Log\LogLevel; $sink = StorageFactory::make([ 'driver' => 'file', 'path' => __DIR__ . '/storage/logs', 'prefix' => 'myapp', 'max_bytes' => '10MB', 'retention_days' => 7, 'max_files' => 30, ]); $logger = new SimpleLogger( appName: 'myapp', env: 'production', sink: $sink, filter: new SensitiveDataFilter(), logging: true, productionMinLevel: LogLevel::ERROR, );
🧠 Runtime Behavior
In production or prod, user-origin logs are skipped unless ['_origin' => 'system'] is set. Levels below productionMinLevel are ignored. Sensitive keys such as password, token, authorization, and client_secret are redacted recursively.
Log records include timestamps, request metadata, PHP runtime details, message text, request IDs, and scrubbed context. Invalid UTF-8 is sanitized before encoding so log writes do not silently fail.
🗃️ File Rotation and Retention
Active files use the pattern prefix-YYYY-MM-DD.log. When max_bytes is exceeded, the current file is renamed to prefix-YYYY-MM-DD_HHMMSS-<token>.log and a fresh active file is created. If configured, retention_days deletes expired matching files and max_files keeps only the newest matching log files.
🚨 Error Handling
The file sink throws RuntimeException when it cannot create the log directory, rotate a file, or append a record. Treat these as operational failures and surface them in deployment monitoring.
🛠️ Development
composer lint
composer analyze
composer test
composer check
composer check runs syntax checks, PHPStan 2.x, and PHPUnit.
memran/marwa-logger 适用场景与选型建议
memran/marwa-logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 922 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 memran/marwa-logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 memran/marwa-logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 922
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-08