aubes/ecs-logging-bundle
Composer 安装命令:
composer require aubes/ecs-logging-bundle
包简介
Symfony bundle providing the Ecs log format
README 文档
README
A Symfony bundle that formats Monolog logs as Elastic Common Schema (ECS) NDJSON, ready to be ingested by Elasticsearch and visualised in Kibana without any index mapping configuration.
Built on top of elastic/ecs-logging.
What's included
| Component | Description |
|---|---|
EcsFormatter |
Produces ECS-compliant NDJSON (log.level lowercase, ecs.version and tags configurable) |
ServiceProcessor |
Injects static service.* metadata (name, version, id…) into every record |
ErrorProcessor |
Converts a \Throwable in context to ECS error.* fields. map_exception_key also catches Symfony's native exceptions |
TracingProcessor |
Maps tracing data to ECS trace.id, transaction.id, span.id (supports manual arrays and OpenTelemetry flat keys) |
CorrelationIdProcessor |
Maps a correlation ID from Monolog extra to ECS labels.correlation_id or trace.id |
UserProcessor |
Injects the authenticated user as ECS user.* via a customisable provider |
HttpRequestProcessor |
Injects ECS http.*, url.*, and optionally client.ip from the current request |
HostProcessor |
Injects static ECS host.* fields resolved once at boot time |
AutoLabelProcessor |
Removes non-ECS context keys to protect the ECS namespace, optionally moving them into labels |
Notable defaults
- Sensitive fields opt-in —
client.ip,url.query,http.request.referrer, anduser.*(PII — see UserProcessor) are disabled by default - FrankenPHP worker mode — stateful processors implement
ResetInterface - ECS namespace protection —
AutoLabelProcessorprevents non-ECS fields from polluting root-level keys - ECS 8.x and 9.x —
ecs.versiondefaults to9.3.0, configurable per deployment
Output example
{
"@timestamp": "2025-03-21T10:00:00.000000+00:00",
"message": "Payment failed",
"ecs.version": "9.3.0",
"log": {
"level": "error",
"logger": "app"
},
"service": {
"name": "checkout",
"version": "1.4.2"
},
"error": {
"type": "RuntimeException",
"message": "Gateway timeout",
"code": "504"
},
"trace": {
"id": "123abc123abc123abc123abc123abc12"
},
"user": {
"name": "alice"
},
"http": {
"request": {
"method": "POST",
"mime_type": "application/json"
},
"version": "1.1"
},
"url": {
"path": "/checkout/pay",
"scheme": "https",
"domain": "shop.example.com"
}
}
Compatibility
- PHP >= 8.2
- Symfony 6.4 | 7.4 | 8.0 — LTS versions only
- Monolog 3.x
- FrankenPHP (worker mode)
- ECS 8.x and 9.x
Installation
composer require aubes/ecs-logging-bundle
Quick start
1. Configure the formatter in Monolog:
# config/packages/monolog.yaml monolog: handlers: main: type: stream path: "%kernel.logs_dir%/%kernel.environment%.log" level: info formatter: 'monolog.formatter.ecs'
2. Enable the bundle and configure at least one processor:
# config/packages/ecs_logging.yaml ecs_logging: monolog: handlers: ['main'] processor: service: enabled: true name: 'my-app' version: '%env(string:APP_VERSION)%'
Documentation
aubes/ecs-logging-bundle 适用场景与选型建议
aubes/ecs-logging-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 502 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 05 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「logging」 「symfony」 「monolog」 「elastic」 「ECS」 「symfony-bundle」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 aubes/ecs-logging-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 aubes/ecs-logging-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 aubes/ecs-logging-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A GeoIP decorator/processor for monolog
The bundle for easy using json-rpc api on your project
A Zend Framework module that sets up Monolog for logging in applications.
Laravel 5.6 Monolog custom telegram channel
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.
PSR-3 compatible logger with dynamic file naming and hourly rotation, powered by Monolog
统计信息
- 总下载量: 502
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-05-01