Lumen日志接入 Elasticsearch
日志分析系统的安装请看部署章节,安装elasticsearch组件
composer require elasticsearch/elasticsearch
修改config/logging.php添加一个elasticsearch配置
'elasticsearch' => [
'driver' => 'monolog',
'handler' => Monolog\Handler\ElasticsearchHandler::class,
'with' => [
'client' => \Elasticsearch\ClientBuilder::create()
->setHosts(explode(',', env('ELASTIC_HOST')))
->build(),
'options' => [
'index' => 'storage-log', // Elastic index name
'type' => '_doc', // Elastic document type
'ignore_error' => false, // Suppress Elasticsearch exceptions
],
],
'formatter' => Monolog\Formatter\ElasticsearchFormatter::class,
'formatter_with' => [
'index' => 'storage-log',
'type' => '_doc',
],
],
bootstrap/app.php 加载该配置
$app->configure('logging');
.env 文件修改
LOG_CHANNEL=elasticsearch
ELASTIC_HOST=es01:9200
《PHP微服务练兵》系列索引: 博客:《PHP 微服务练兵》系列教程
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: