sentry2 php,yii2日志组件,Sentry日志收集,kafka消息队列

日志系统

web.php配置'log' => [

'travelevel'=> YII_DEBUG ? 3 : 0;//追踪级别

'targets' => [

[

‘class’ => 'yii\log\FileTarget',  //文件

'levels' => ['error', 'warning'],  //记录的错误级别

‘logFile’ => '@app/runtime/logs/shop/application.log',  //指定日志文件位置

],

[

'class' =>  'yii\log\FileTarget',

'levels' => ['info', 'trace'],

'logFile' => '@app/runtime/logs/shop/info.log',

'categories' => ['myinfo'], //指定分类 Yii::info('this is info', myinfo);

'logVars' => [],  //不记默认的

],

[ //邮件日志,不建议使用,速度慢

'class' => 'yii\log\EmailTarget',

'mailer' => 'mailer',

'levels' => ['error', 'warning'],

'message' => [

'from' => ['imooc_shop@163.com'],

'to' => ['86267659@qq.com'],

'subject' => 'imooc_shop的日志'

],

],

],

]

写日志Yii::trace('this is trace');  //levels中要增加trace     'levels' => ['trace', 'error', 'warning']

Yii::info('this is info');  //'levels' => ['info', 'trace', 'error', 'warning']

性能分析Yii::beginProfile('mybench');

Yii::endProfile('mybench');

Sentry日志收集,官网sentry.io,github搜索安装Yii2 Sentry(mito/yii2-sentry)'sentry' => [

'class' => 'mito\sentry\SentryComponent',

'dsn' => 'https://b54b26f05efd42e8879e957cb7d76273:93014636f46a4620a40ca35155385e56@sentry.io/122995', // private DSN

'publicDsn' => 'https://b54b26f05efd42e8879e957cb7d76273@sentry.io/122995',

'environment' => YII_CONFIG_ENVIRONMENT, // if not set, the default is `development`

'jsNotifier' => true, // to collect JS errors

'clientOptions' => [ // raven-js config parameter

'whitelistUrls' => [ // collect JS errors from these urls 为空收集所有

//'http://staging.my-product.com',

//'https://my-product.com',

],

],

],

c8406faf5374ab73021b86b1660e5902.png

kafka消息队列

流量大时redis队列不可靠

需要一台新服务器,wget下载kafka,解压,进入

进入config文件夹,主要做两个配置:server.properties 和 zookeeper.properties

server

d79ceb3046662f2eed9775d2114fa47c.png

启动(安装java-jdk)

bin/zookeeper-service-start.sh config/zookeeper.properties

bin/kafka-server-start.sh config/server.properties

启动消费者

bin/kafka-console-consumer.sh –zookeeper localhost:2181 –topic test –from-beginning

启动生产者

bin/kafka-sonsole-producer.sh –broker-list 192.168.199.150:9092 –topic test

生产者端生产消息,消费者端能收到消息

php操作kafka

安装kafka拓展

github搜librdkafka

./configure

make && make install

github搜php-rdkafka

phpize

./configure –with-php-config=/usr/local/php/bin/php-config

make && make install

之后会在/usr/local/php/lib/php/extensions/no-debug-non-zts-20131223/中生产so文件

php.ini中配置

84273e3f293f3fdf9364d135f015de49.png

php -m查看拓展

编写kafka类

web.php中添加

4bd529d368ff1927158b8d940774893c.png

Yii::$app->asyncLog->send([‘this is indexcontroller’]); //发送消息

console.php中增加配置

899e53ea9f25b22847a08bcc5c2d853e.png

dbe1f2a885eb2dacf1f028fdc3c5541b.png

commands中建立KafkaController.php

命令调用 ./yii kafka/consume

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值