james-ban / yii2-logstash
yii2 logstash
v0.1
2019-11-11 07:35 UTC
Requires
- php: >=5.5
- ext-json: *
- yiisoft/yii2: ~2.0.14
This package is auto-updated.
Last update: 2024-05-29 04:41:07 UTC
README
Yii2配置
-
安装
composer require james-ban/yii2-logstash
-
修改
app/config/web.php
添加LogstashFileTarget
部分<?php .... 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [ .... [ 'class' => 'Log\LogstashFileTarget', 'levels' => ['error', 'warning'], 'except' => ['yii\web\HttpException:404', 'yii\web\HttpException:403', 'yii\debug\Module::checkAccess', 'yii\web\HttpException:400', 'yii\base\UserException', 'yii\web\HttpException:401'], 'logFile' => '@runtime/logs/logstash.log', ] .... ], ], ..... ?>
Logstatsh配置文件
- 将
yii2.conf
放置在/etc/logstash/conf.d
下
input {
file {
type => "prod"
path => "$project_path/app/runtime/logs/logstash.log"
#start_position => "end"
codec => "json"
}
}
output {
if [type] == "prod" {
elasticsearch {
hosts => ["$elasticsearch_host:$elasticsearch_port"]
index => "yii-web-%{+YYYY-MM-dd}"
document_type => "yii2"
workers => 1
#flush_size => 20000
#idle_flush_time => 10
}
}
}
-
重启 logstatsh
# /etc/init.d/logstash Usage: {start|stop|force-stop|status|reload|restart|configtest}