clearcode / simple-bus-elk-bundle
Symfony2 的 ELK 集成
dev-master / 0.1.x-dev
2016-01-27 09:15 UTC
Requires
- php: >=5.6
- jms/serializer-bundle: ~1.1
- psr/log: ^1.0
- simple-bus/message-bus: ~2.0
- symfony/framework-bundle: ~2.5
- symfony/monolog-bundle: ~2.4
Requires (Dev)
- phpunit/phpunit: ~5.0
- satooshi/php-coveralls: ^0.7.1
This package is not auto-updated.
Last update: 2024-09-14 18:58:23 UTC
README
Symfony2 的 ELK 桥接器
使用方法
需求
安装 ELK,配置 Logstash
input {
tcp {
port => 5000
codec => "json"
}
}
output {
elasticsearch { }
}
已在 ELK docker 上测试:https://github.com/deviantony/docker-elk
安装与配置
I. 注册一个包
<?php class AppKernel extends Kernel { public function registerBundles() { $bundles = array( ... new Clearcode\SimpleBusElkBundle\SimpleBusElkBundle(), ... ) } ... }
II. 在您的配置文件中添加此行
simple_bus_elk: middleware: true logstash_namespace: your_app monolog_channel: simple_bus_elk monolog: channels: ["simple_bus_elk"] handlers: simple_bus_logstash: type: socket connection_string: localhost:5000 // <-- this part can be parametrized! level: debug channels: ["simple_bus_elk"] formatter: simple_bus_elk.monolog.logstash_formatter // <-- you can use our default, beautiful formatter or write your own if you want to!
III. 在服务中启用 monolog 日志记录器
-
如果您使用 SimpleBus 包,只需将
simple_bus_elk.middleware
设置为true
。它将启用事件中间件,自动在 ELK 上记录您的事件。 -
否则,只需使用我们的 monolog 通道,如下所示
services: service.do_amazing_thing: ... arguments: ... - @logger tags: ... - { name: monolog.logger, channel: '%simple_bus_elk.channel%' }
(以 Clearcode\SimpleBusElkBundle\CommandBus\LogEventMiddleware 为例)
注意
simple_bus_elk.logstash_namespace
将记录在 Kibana 的 @type
字段中。我们建议将其更改为您希望记录事件的项目的名称(如果在一个 ELK 实例中记录多个项目的事件,这一点尤为重要)。
simple_bus_elk.channel
将记录在 Kibana 的 @fields.channel
& @tags
字段中。当您在同一个 Kibana 的索引模式中记录 ELK 实例中的其他内容时,这一点很重要。