maatify/slim-logger
最新稳定版本:1.0.6
Composer 安装命令:
composer require maatify/slim-logger
包简介
Slim-compatible structured logger with PSR-7 request support
README 文档
README
Maatify Slim Logger is a lightweight, PSR-7 compatible, Slim-friendly structured logger for PHP applications. It is part of the modular Maatify ecosystem.
🚀 Features
- ✅ PSR-7 request-aware logging (integrates with Slim Framework)
- ✅ Uses
LogLevelEnum(PHP 8.1+) - ✅ Logs to file in JSON format
- ✅ File names include log level (
_response_error_...) - ✅ Static access with
Logger::recordStatic() - ✅ Automatically creates secure log directories
- ✅ Works with Slim or pure PHP
- ✅ GitHub Actions CI ready
📦 Installation
composer require maatify/slim-logger
🧱 Namespaces
- Logger:
Maatify\SlimLogger\Log\Logger - Enum:
Maatify\SlimLogger\Log\LogLevelEnum - Path Helper:
Maatify\SlimLogger\Store\File\Path
📁 Folder Structure
maatify-slim-logger/
├── src/
│ └── Log/
│ ├── Logger.php
│ └── LogLevelEnum.php
│ └── Store/
│ └── File/
│ └── Path.php
✅ Basic Usage (Slim or Plain PHP)
use Maatify\SlimLogger\Log\Logger; use Maatify\SlimLogger\Log\LogLevelEnum; use Maatify\SlimLogger\Store\File\Path; $logger = new Logger(new Path(__DIR__)); $logger->record('User login', null, 'user/actions', LogLevelEnum::Info);
💡 Usage in Slim Route
$app->post('/action', function ($request, $response) use ($logger) { $logger->record('User posted action.', $request, 'user/submit', LogLevelEnum::Debug); return $response; });
⚠️ Logging Exceptions
try { throw new \Exception('Oops'); } catch (\Throwable $e) { $logger->record($e, null, 'errors/runtime', LogLevelEnum::Error); }
📣 Static Logging
Log from anywhere — no need to instantiate:
use Maatify\SlimLogger\Log\Logger; use Maatify\SlimLogger\Log\LogLevelEnum; Logger::recordStatic('Static log entry.', null, 'system/status', LogLevelEnum::Info);
✅ Static Exception Example
try { throw new \Exception("Static exception!"); } catch (\Throwable $e) { Logger::recordStatic($e, null, 'errors/fatal', LogLevelEnum::Error); }
🧪 (Advanced) Overriding Static Instance for Testing
In PHPUnit or setup environments, use:
$testLogger = new Logger(new Path(__DIR__ . '/logs')); Logger::setInstance($testLogger);
Then recordStatic() will use that injected instance and path.
🔍 Log File Naming Example
/logs/24/04/18/user/actions_response_info_20250418AM.log
⚙️ Configuration
| Option | Default | Description |
|---|---|---|
Path |
project root | Base path for log files |
Extension |
.log |
File extension for log files |
🧪 Run Tests Locally
composer test
🚀 GitHub CI Integration
Tests run automatically on push via:
.github/workflows/run-tests.yml
📄 License
MIT License © 2025 Maatify.dev
🙋♂️ Questions?
- GitHub: github.com/maatify/slim-logger
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-17