ez-php/logging
Composer 安装命令:
composer require ez-php/logging
包简介
Logging module for the ez-php framework — structured logging with file, stdout, and null drivers
关键字:
README 文档
README
Logging module for the ez-php framework — structured logging with pluggable drivers, minimum-level filtering, JSON formatting, request context injection, and automatic exception logging.
Requirements
- PHP 8.5+
- ez-php/framework 0.*
Installation
composer require ez-php/logging
Setup
Register the service provider:
$app->register(\EzPhp\Logging\LogServiceProvider::class);
Configure in config/logging.php:
return [ 'driver' => env('LOG_DRIVER', 'file'), // file | stdout | null | json | stack 'path' => env('LOG_PATH', 'storage/logs'), 'min_level' => env('LOG_MIN_LEVEL', ''), // DEBUG|INFO|WARNING|ERROR|CRITICAL — empty = all 'json_inner'=> env('LOG_JSON_INNER', 'stdout'), // inner driver when driver=json 'stack' => ['file', 'stdout'], // used when driver=stack ];
Usage
use EzPhp\Logging\Log; Log::debug('Cache miss', ['key' => 'users.all']); Log::info('User registered', ['id' => 42]); Log::warning('Rate limit approaching', ['remaining' => 5]); Log::error('Payment failed', ['order' => 'ORD-99']); Log::critical('Database unreachable'); // Generic level dispatch Log::log('info', 'Something happened');
Drivers
| Driver | Description |
|---|---|
file |
Appends to {path}/app-YYYY-MM-DD.log (daily rotation) |
stdout |
debug/info/warning → stdout · error/critical → stderr |
null |
Discards all entries — useful in tests |
json |
Decorator: serialises entries as JSON and forwards to an inner driver |
stack |
Decorator: fans each call out to multiple inner drivers simultaneously |
Wrap any driver with a minimum-level filter by setting LOG_MIN_LEVEL:
LOG_DRIVER=file LOG_MIN_LEVEL=WARNING # drops DEBUG and INFO entries
JSON structured logging
LOG_DRIVER=json LOG_JSON_INNER=stdout
Each entry is written as a single JSON line:
{"timestamp":"2026-03-21T12:00:00+00:00","level":"info","message":"tick.event","context":{"user_id":5}}
Stack driver
Write to multiple destinations simultaneously:
LOG_DRIVER=stack
// config/logging.php return [ 'driver' => 'stack', 'stack' => ['file', 'stdout'], ];
Request context middleware
RequestContextMiddleware injects request_id, ip, method, and path into every log entry produced during a request:
$app->middleware(\EzPhp\Logging\RequestContextMiddleware::class);
The middleware wraps the current logger in a ContextualLogger and restores the original logger in finally.
Exception logging
LogServiceProvider automatically wraps the ExceptionHandler with LoggingExceptionHandler, so all unhandled exceptions are logged at error level (with exception class, code, file, and line) before the response is rendered. No extra configuration needed.
Log format (file/stdout)
[2026-03-15 12:00:00] INFO: User registered {"id":42}
[2026-03-15 12:00:01] ERROR: Payment failed {"order":"ORD-99"}
Classes
| Class | Description |
|---|---|
LoggerInterface |
Contract: log(), debug(), info(), warning(), error(), critical() |
LogLevel |
Backed enum: DEBUG|INFO|WARNING|ERROR|CRITICAL; severity(), isAtLeast() |
FileDriver |
Appends to daily-rotated log files; creates directory on demand |
StdoutDriver |
stdout for debug/info/warning, stderr for error/critical |
NullDriver |
No-op — discards all entries |
JsonDriver |
Decorator: serialises entries as JSON, forwards to inner driver |
StackDriver |
Decorator: fans calls out to a list of inner drivers |
MinLevelDriver |
Decorator: drops entries below a configured minimum severity |
ContextualLogger |
Decorator: merges a fixed context array into every log call |
RequestContextMiddleware |
Injects request_id/ip/method/path context for the duration of a request |
Log |
Static façade backed by a managed LoggerInterface singleton |
LoggingExceptionHandler |
Decorator: logs exceptions at error level, then delegates to inner handler |
LogServiceProvider |
Config-driven driver binding; wraps ExceptionHandler; wires Log façade |
License
MIT — Andreas Uretschnig
ez-php/logging 适用场景与选型建议
ez-php/logging 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「logging」 「framework」 「php」 「logger」 「ez-php」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ez-php/logging 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ez-php/logging 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ez-php/logging 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
A Zend Framework module that sets up Monolog for logging in applications.
Asynchronous Sentry for Symfony - Fire and forget
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
High-performance, zero-dependency PSR-3 logger for MonkeysLegion with structured logging, handlers, processors, and PHP 8.4 features.
Audit changes of your Eloquent models in Laravel/Lumen
统计信息
- 总下载量: 30
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 40
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-15