noerdisch / elasticlog
使用 elasticsearch 的 Neos Flow 记录后端
Requires
- neos/flow: >4.2.0
- ruflin/elastica: ^5.3
README
Nœrdisch ElasticLog
Noerdisch.ElasticLog Flow 包将异常和单条消息记录到配置的 elasticsearch 服务器。此包还提供后端,将 Flows Logger 类的消息记录到 elasticsearch 服务器。
安装 & 配置
只需将 "noerdisch/elasticlog" 添加到 composer.json 中的依赖项,并在项目的根目录中运行 "composer update",或者简单地从项目的根目录执行
composer require noerdisch/elasticlog
。
配置您的 Elastic 服务器
Noerdisch: ElasticLog: Connection: host: '127.0.0.1' port: 9200 index: 'myIndex42'
我们提供了一个命令控制器来设置您 elastic search 索引。您可以使用它来创建索引或重置记录器。
./flow elasticindex:setup
手动记录
如果您希望将常规日志消息记录到您的 elastic 服务器,请使用提供的 ElasticLoggerInterface
use Neos\Flow\Annotations as Flow; use Noerdisch\ElasticLog\Log\ImportLoggerInterface; class SomeClass { /** * @Flow\Inject * @var ImportLoggerInterface */ protected $logger; public function yourMethod() { try { $this->callSomeMethod(); } catch (Exception $exception) { $this->logger->logThrowable($exception, ['identifier' => 'foo']); } } }
默认情况下,当 Flow 在 Development
上下文中运行时,消息也将记录到 SystemLoggerInterface
。您可以使用设置启用或禁用此功能
Noerdisch: ElasticLog: Logger: backendOptions: alsoLogWithSystemLogger: true
记录后端
要将 ElasticBackend 配置为默认记录后端,请在 Settings.yaml 中添加以下内容
Neos:
Flow:
log:
systemLogger:
backend: Noerdisch\ElasticLog\Log\Backend\ElasticBackend
securityLogger:
backend: Noerdisch\ElasticLog\Log\Backend\ElasticBackend
sqlLogger:
backend: Noerdisch\ElasticLog\Log\Backend\ElasticBackend
i18nLogger:
backend: Noerdisch\ElasticLog\Log\Backend\ElasticBackend
记录异常
激活异常处理器,并在 Settings.yaml 中配置与您的 elasticsearch 服务器之间的连接
Neos: Flow: error: exceptionHandler: className: 'Noerdisch\ElasticLog\Error\ElasticLogExceptionHandler'
现在,所有显示在 Web 或 CLI 中的异常都将记录到 elastic。
注意:对于 Development
上下文,Neos.Flow 包将覆盖此设置。请确保在正确的上下文 Settings.yaml 中添加此配置。
如果您想将所有异常都记录到 elasticsearch,还应替换系统记录器。这将记录所有通过 SystemLogger 记录的错误,并将它们同时记录到 ElasticLog 和磁盘上。默认情况下,Flow 只会将单行记录到系统日志,即 "另请参阅 ... .txt"。ElasticLogger 也会记录完整的异常。
Neos: Flow: log: systemLogger: logger: Noerdisch\ElasticLog\Log\ElasticLogger
过滤异常
要跳过某些异常的记录,您可以使用 skipStatusCodes
设置
Noerdisch: ElasticLog: # don't log any exceptions that would result in a HTTP status 403 (access denied) / 404 (not found) skipStatusCodes: [403, 404]
感谢
该包是在 Yeebase 的 Graylog 包的基础上构建的。感谢 Yeebase 的朋友分享它。请查看他们在 github 上的存储库。他们也 ❤️ Neos 和 Neos flow 框架。
我们不使用 Graylog,因为我们想利用 elastic 提供的整个 ELK 堆栈。