日誌分析系統的安裝請看部署章節,安裝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 協議》,轉載必須註明作者和本文連結