suver / yii2-logger

Yii2的日志目标

安装: 532

依赖: 0

建议者: 0

安全性: 0

星标: 1

关注者: 1

分支: 0

开放问题: 0

类型:yii2-extension

1.0.3-stable 2017-04-26 14:03 UTC

This package is not auto-updated.

Last update: 2024-09-20 22:18:00 UTC


README

致谢

Benjamin Zikarsky https://github.com/bzikarsky/gelf-php

安装

安装此扩展的首选方法是通过Composer

运行以下命令之一:

php composer.phar require "suver/yii2-logger" "*"

或者将以下内容添加到你的应用程序的composer.json文件的require部分:

"suver/yii2-logger" : "*"

使用方法

将Graylog目标添加到你的日志组件配置中

<?php
return [
    ...
    'components' => [
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                'file' => [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
                'graylog' => [
                    'class' => 'suver\logger\GraylogTarget',
                    'levels' => ['error', 'warning', 'info'],
                    'categories' => ['application'],
                    'logVars' => [], // This prevent yii2-debug from crashing ;)
                    'type' => 'udp', // tcp, udp, amqp
                    'transport' => [
                        'host' => 'graylog',
                        'port' => '12201',
                    ],
                    'facility' => 'facility-name',
                ],
            ],
        ],
    ],
    ...
];
<?php
// short_message will contain string representation of ['test1' => 123, 'test2' => 456],
// no full_message will be sent
Yii::info([
    'test1' => 123,
    'test2' => 456,
]);

// short_message will contain 'Test short message',
// two additional fields will be sent,
// full_message will contain all other stuff without 'short' and 'add':
// string representation of ['test1' => 123, 'test2' => 456]
Yii::info([
    'test1' => 123,
    'test2' => 456,
    'short' => 'Test short message',
    'add' => [
        'additional1' => 'abc',
        'additional2' => 'def',
    ],
]);

// short_message will contain 'Test short message',
// two additional fields will be sent,
// full_message will contain 'Test full message', all other stuff will be lost
Yii::info([
    'test1' => 123,
    'test2' => 456,
    'short' => 'Test short message',
    'full' => 'Test full message',
    'add' => [
        'additional1' => 'abc',
        'additional2' => 'def',
    ],
]);