devgroup / yii2-graylog-target
Yii2框架应用的Graylog2日志目标
Requires
- php: >=5.5
- graylog2/gelf-php: ~1.5
- psr/log: ~1.0.2
- yiisoft/yii2: ~2.0
Requires (Dev)
- codeception/codeception: ^2.2
This package is not auto-updated.
Last update: 2024-09-15 01:17:22 UTC
README
Yii2框架应用的Graylog2日志目标
安装
要在项目中作为composer依赖安装yii2-graylog-target库,请运行以下命令
php composer.phar require "devgroup/yii2-graylog-target:*"
... 或者直接在composer.json文件中添加以下行
"devgroup/yii2-graylog-target": "*"
配置
从配置数组中进行配置
'components' => [ 'log' => [ 'grayii' => [ 'transport' => [ 'class' => \Gelf\Transport\HttpTransport::class, 'host' => 'http://graylog2-server.com', 'port' => 12201, ], 'appName' => 'app name', ] ] ]
可用的配置参数
使用方法
-
发送附加数据
Yii::info([ 'short' => 'Short message or title', // required. alternate usage variant: `Short message or title` (without a key 'short', but first item in array) 'full' => 'Full message', // optional. full message of log. For example, may be a stack trace as string or other detalized message '_field1' => 'value1', // optional. additional field starts with '_' symbol '_field2' => 'value2', // optional. additional field starts with '_' symbol ]);
-
发送异常
try { ... running code with harmful bugs... } catch (\Throwable $t) { Yii::warning($t); }
-
发送简短消息
Yii::trace('The short message example'); // or equivalent usage is Yii::trace(['The short message example']);
测试
测试被放置在test目录中。可以通过以下命令运行测试
php composer.phar exec codecept run
使用docker在不同版本的PHP上进行测试
-
PHP v5.6
docker run -it --rm --name php56-for-grayii-tests -v "$PWD":/usr/src/myapp -w /usr/src/myapp php:5.6-cli php vendor/bin/codecept run
-
PHP v7.0
docker run -it --rm --name php70-for-grayii-tests -v "$PWD":/usr/src/myapp -w /usr/src/myapp php:7.0-cli php vendor/bin/codecept run
-
HHVM
docker run -it --rm --name hhvm-for-grayii-tests -v "$PWD":/usr/src/myapp -w /usr/src/myapp diegomarangoni/hhvm:cli hhvm vendor/bin/codecept run