flytachi/winter-logger
Composer 安装命令:
composer require flytachi/winter-logger
包简介
Multi-runtime PSR-3 logger for Winter framework (FPM, Swoole, CLI)
README 文档
README
flytachi/winter-logger — multi-runtime PSR-3 logger for the Winter framework. Wraps Monolog with coroutine-safe context isolation, Spring Boot-style output, and a Java-style static factory.
The library is infrastructure-agnostic: it knows nothing about env vars, Docker, SAPI, or Swoole detection — that responsibility belongs to the framework that boots it.
Requirements
- PHP >= 8.3
psr/log^3.0monolog/monolog^3.5 (suggested — without it every logger silently becomesNullLogger)ext-swoole(optional — required only forCoroutineContext)
Installation
composer require flytachi/winter-logger monolog/monolog
Monolog-free (every logger will be a no-op NullLogger):
composer require flytachi/winter-logger
Quick Start
1. Build a LoggerManager
The manager accepts a ready-made config — the framework resolves env vars and infrastructure details before calling this:
use Monolog\Level; use Flytachi\Winter\Logger\LoggerManager; use Flytachi\Winter\Logger\Context\ProcessContext; // FPM / CLI // use Flytachi\Winter\Logger\Context\CoroutineContext; // Swoole $manager = new LoggerManager( contextStorage: new ProcessContext(), channels: [ 'http' => [ 'level' => Level::Info, 'format' => 'line', // 'line' | 'json' 'output' => 'stderr', // 'stdout' | 'stderr' | 'syslog' | 'file' | 'null' 'file_path' => null, 'file_max' => 30, 'syslog_ident' => 'winter', ], 'cli' => [ 'level' => Level::Debug, 'format' => 'line', 'output' => 'stdout', 'file_path' => null, 'file_max' => 30, 'syslog_ident' => 'winter', ], ], );
2. Register with LoggerFactory
use Flytachi\Winter\Logger\LoggerFactory; LoggerFactory::setManager($manager);
3. Log from anywhere
use Flytachi\Winter\Logger\LoggerFactory; // Per-class logger — Java-style: LoggerFactory::getLogger(UserService::class, 'http')->info('user created', ['id' => 42]); LoggerFactory::getLogger($this, 'cli')->debug('job started'); // Raw channel: LoggerFactory::channel('http')->warning('rate limit hit'); // Bound context — fields appear in every subsequent call: $log = LoggerFactory::getLogger(self::class, 'http')->withContext(['request_id' => $id]); $log->info('processing'); $log->info('done');
Output (line format)
[2024-01-01 12:00:00] [INFO ] -http- [4821] (UserService): user created {"id":42,"class":"App\\Service\\UserService"}
[2024-01-01 12:00:00] [WARN ] -http- [4821]: rate limit hit
Request-scoped context
Set fields once at the start of a request/job and they appear in every log line
automatically via ContextInjectingProcessor:
// At request start (FPM middleware / Swoole onRequest): $manager->contextStorage()->set('request_id', $requestId); $manager->contextStorage()->set('user_id', $userId); // At request end — must clear in long-running processes to prevent leaks: $manager->contextStorage()->clear();
For Swoole use CoroutineContext — it isolates context per coroutine so
concurrent requests never bleed into each other.
Channel config reference
| Key | Type | Description |
|---|---|---|
level |
Monolog\Level |
Minimum level to handle |
format |
'line' | 'json' |
Log format |
output |
'stdout' | 'stderr' | 'syslog' | 'file' | 'null' |
Where to write |
file_path |
string|null |
Required when output=file |
file_max |
int |
Max rotated files to keep (default 30) |
syslog_ident |
string |
Syslog process identifier (default 'winter') |
Processors
ContextInjectingProcessor is added to every channel automatically — no config needed.
SensitiveMaskingProcessor is optional. Add it after building the manager:
use Flytachi\Winter\Logger\Processor\SensitiveMaskingProcessor; $monolog = $manager->channel('http')->monolog(); $monolog->pushProcessor(new SensitiveMaskingProcessor(['my_secret']));
Default masked keys: password, token, secret, api_key, authorization,
cookie, credit_card, cvv, ssn, pin, and more.
Documentation
| File | Topic |
|---|---|
| 00-overview.md | Architecture — how the pieces fit together |
| 01-installation.md | Installation, optional Monolog |
| 02-channels.md | LoggerManager, channel config, output types |
| 03-logger-factory.md | LoggerFactory, getLogger, withContext |
| 04-context.md | ProcessContext, CoroutineContext, lifecycle |
| 05-handlers-formatters.md | SafeStreamHandler, formatters, broken pipe |
| 06-processors.md | ContextInjectingProcessor, SensitiveMaskingProcessor |
License
MIT License. See LICENSE.
flytachi/winter-logger 适用场景与选型建议
flytachi/winter-logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 167 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「monolog」 「logger」 「psr-3」 「fpm」 「swoole」 「winter」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 flytachi/winter-logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 flytachi/winter-logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 flytachi/winter-logger 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A GeoIP decorator/processor for monolog
A Zend Framework module that sets up Monolog for logging in applications.
Laravel 5.6 Monolog custom telegram channel
Workflow logger
HTTP request logger middleware for Laravel
A Monolog processor to add X-Request-Id or UNIQUE_ID env to monolog stack if present, provide a default one otherwise. Optionally, add a forwarded request-id list.
统计信息
- 总下载量: 167
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 45
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-29