项目作者: jamesBan

项目描述 :
yii2-logstash
高级语言: PHP
项目地址: git://github.com/jamesBan/yii2-logstash.git
创建时间: 2017-08-12T08:02:37Z
项目社区:https://github.com/jamesBan/yii2-logstash

开源协议:

下载


yii2-logstash

Yii2配置

  • 安装

    1. composer require james-ban/yii2-logstash
  • 修改 app/config/web.php 添加LogstashFileTarget 部分

    1. <?php
    2. ....
    3. 'log' => [
    4. 'traceLevel' => YII_DEBUG ? 3 : 0,
    5. 'targets' => [
    6. ....
    7. [
    8. 'class' => 'Log\LogstashFileTarget',
    9. 'levels' => ['error', 'warning'],
    10. 'except' => ['yii\web\HttpException:404', 'yii\web\HttpException:403', 'yii\debug\Module::checkAccess', 'yii\web\HttpException:400', 'yii\base\UserException', 'yii\web\HttpException:401'],
    11. 'logFile' => '@runtime/logs/logstash.log',
    12. ]
    13. ....
    14. ],
    15. ],
    16. .....
    17. ?>

Logstatsh配置文件

  • yii2.conf放置在/etc/logstash/conf.d

    1. input {
    2. file {
    3. type => "prod"
    4. path => "$project_path/app/runtime/logs/logstash.log"
    5. #start_position => "end"
    6. codec => "json"
    7. }
    8. }
    9. output {
    10. if [type] == "prod" {
    11. elasticsearch {
    12. hosts => ["$elasticsearch_host:$elasticsearch_port"]
    13. index => "yii-web-%{+YYYY-MM-dd}"
    14. document_type => "yii2"
    15. workers => 1
    16. #flush_size => 20000
    17. #idle_flush_time => 10
    18. }
    19. }
    20. }
  • 重启 logstatsh

    1. # /etc/init.d/logstash
    2. Usage: {start|stop|force-stop|status|reload|restart|configtest}