pouyaniarmin/pulse-logger
Composer 安装命令:
composer require pouyaniarmin/pulse-logger
包简介
PulseLogger is a lightweight and flexible PHP logging library.
README 文档
README
PulseLogger is a lightweight and easy-to-use PHP logging library.
It supports text and JSON logging, provides detailed log metadata, and follows the Singleton pattern for consistent logging across your application.
Features
| Feature | Description |
|---|---|
| Singleton Logger | Consistent logging across the application. Calling getInstance() always returns the same logger instance. |
| TextFormatter & JsonFormatter | Supports both text and JSON output. |
| Configurable Log Path | The log path must be initialized once using init() before logging. Once set, it is used globally across your application, no need to re-initialize in controllers or classes. |
| Detailed Metadata | Timestamp, Level, Message, File, Class, Function, Request ID, Client IP. |
| JSON Lines | Each JSON entry is a single object, easy for programmatic processing. |
| Text Separator | Adds a separator line for readability in text logs. |
Installation
PulseLogger can be installed via Composer in your project:
composer require pouyaniarmin/pulse-logger
Usage / Examples
Basic Setup
<?php require_once "./vendor/autoload.php"; use Armin\PulseLogger\PulseLogger; // Initialize logger with mandatory log path (once) $logger = PulseLogger::getInstance(); $logger->init(__DIR__ . '/logs'); // Log an informational message in text format $logger->info('text', 'Application started successfully.'); // Log an error message in JSON format $logger->error('json', 'Failed to connect to the database.');
Example in a Class
<?php class UserService { public function fetchUserData(int $userId) { $logger = PulseLogger::getInstance(); $logger->info('text', "Fetching user data for user ID: $userId"); $url = "https://api.example.com/users/$userId"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); if (curl_errno($ch)) { // Logger path already initialized in bootstrap, no need to init again $logger->error('json', "Error fetching user data: " . curl_error($ch)); } else { $logger->info('text', "User data fetched successfully for user ID: $userId"); } curl_close($ch); return $response; } } // Usage example $service = new UserService(); $userData = $service->fetchUserData(42); echo $userData;
Log Files / Output
PulseLogger creates log files in your specified log directory.
-
Text logs:
logs/app.log- Each entry is formatted as key:value pairs
- A separator line (
--------------------------------------------------) is added between entries for readability
-
JSON logs:
logs/json.log- Each entry is a JSON object on a separate line (JSON Lines format)
- Useful for processing logs programmatically or with tools like ELK stack
Contributing
Contributions to PulseLogger are welcome!
- Feel free to open issues if you find bugs or have feature requests.
- You can submit pull requests to improve the library or add new features.
- Please follow PSR-12 coding standards for PHP code.
- Make sure to write clear commit messages for your changes.
License
PulseLogger is licensed under the MIT License.
You are free to use, modify, and distribute this software, as long as you include the original license notice.
pouyaniarmin/pulse-logger 适用场景与选型建议
pouyaniarmin/pulse-logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 pouyaniarmin/pulse-logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pouyaniarmin/pulse-logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-14