logger/errorhandling
Composer 安装命令:
composer require logger/errorhandling
包简介
Errorhandling extension for PSR-3 compatible loggers
README 文档
README
Overview
- ErrorHandling provides drop‑in handlers that route all PHP problems to your PSR‑3 logger: notices, warnings, deprecations, assertions, exceptions, and many fatals.
- Designed for modern PHP (8.x, incl. 8.5) and integrates with logger/essentials out of the box, but works with any PSR‑3
LoggerInterface.
Requirements
- PHP >= 8.0
- A PSR‑3 compatible logger (e.g.,
logger/essentials)
Install
- Composer:
composer require logger/errorhandling
Quick Start
use Logger\CoreErrorHandlers; use Psr\Log\LogLevel; // Turn PHP errors into exceptions (configurable mask, defaults to E_ALL) CoreErrorHandlers::enableExceptionsForErrors(); // Log assertions through your PSR-3 logger at a chosen level CoreErrorHandlers::registerAssertionHandler($logger, LogLevel::WARNING); // Log uncaught exceptions (and print a compact stack trace to STDERR) CoreErrorHandlers::registerExceptionHandler($logger); // Log fatal errors such as E_ERROR/E_PARSE/E_CORE_ERROR/E_COMPILE_ERROR CoreErrorHandlers::registerFatalErrorHandler($logger);
What It Does
- Exceptions for errors: Converts PHP error levels (by bitmask) into
ErrorExceptionyou can catch, or let bubble into the exception handler. - Assertion logging: Captures
assert()callbacks and logs message + file/line without emitting warnings. - Exception logging: Catches uncaught
Throwable, logs atcritical, and prints a readable stack trace to STDERR before exiting with status 1. - Fatal error logging: On shutdown, inspects the last error and logs
alertfor typical fatal types.
API
CoreErrorHandlers::enableExceptionsForErrors(int $bitmask = E_ALL): void- Throw
ErrorExceptionfor any error whose level matches$bitmask.
- Throw
CoreErrorHandlers::registerAssertionHandler(LoggerInterface $logger, string $logLevel): void- Route failed assertions to
$loggerat the given PSR‑3 level, withfileandlinecontext.
- Route failed assertions to
CoreErrorHandlers::registerExceptionHandler(LoggerInterface $logger): void- Log uncaught exceptions as
criticalwith rich context; prints stack trace and exits with code 1.
- Log uncaught exceptions as
CoreErrorHandlers::registerFatalErrorHandler(LoggerInterface $logger): void- On shutdown, log last fatal error (
E_ERROR,E_PARSE,E_CORE_ERROR,E_COMPILE_ERROR) asalert.
- On shutdown, log last fatal error (
Configuration Tips
- Call the registration methods early in your bootstrap so problems are captured.
- You can combine handlers (typical usage registers all of them).
- To exclude specific severities from becoming exceptions, pass a masked bitmask, e.g.
E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED.
Development
- Run tests:
composer run tests - Static analysis:
composer run phpstan
Compatibility Notes
E_STRICTis not handled specially (folded into other levels on modern PHP).- Handlers use
Throwable, not justException, to cover engine errors in PHP 7/8.
License
- MIT — see LICENSE for details.
logger/errorhandling 适用场景与选型建议
logger/errorhandling 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.29k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2014 年 11 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 logger/errorhandling 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 logger/errorhandling 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.29k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-11-20