asminog/yii2-sentry

为 Sentry 定制的 Yii2 日志器

安装次数: 65

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 3

分支: 0

开放问题: 0

类型:yii2-extension

v1.1.1 2020-04-07 15:54 UTC

This package is auto-updated.

Last update: 2024-09-22 16:20:52 UTC


README

Latest Stable Version Test License PHP from Packagist Code Intelligence Status Scrutinizer code quality Downloads

安装

composer require asminog/yii2-sentry

在应用程序配置中添加目标类

return [
    'components' => [
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'asminog\yii2sentry\SentryTarget',
                    'levels' => ['error', 'warning'],
                    'dsn' => 'https://88e88888888888888eee888888eee8e8@sentry.io/1',
//                    release option for project, default: null. Use "auto" to get it from git exec('git log --pretty="%H" -n1 HEAD')
                    'release' => 'my-project-name@2.3.12',
//                    Options for sentry client
                    'options' => [],
//                    Collect additional context from $_GLOBALS, default: ['_SESSION', 'argv']. To switch off set false.
                    /* @see https://docs.sentry.io/enriching-error-data/context/?platform=php#extra-context
                    'collectContext' => ['_SERVER', '_COOKIE', '_SESSION', 'argv'],
                    // user attributes to collect, default: ['id', 'username', 'email']. To switch off set false.
                    /* @see https://docs.sentry.io/enriching-error-data/context/?platform=php#capturing-the-user */
                    'collectUserAttributes' => ['userId', 'userName', 'email'],
                    // add something to extra using extraCallback, default: null
                    'extraCallback' => function ($message, $extra) {
                        $extra['YII_ENV'] = YII_ENV;
                        return $extra;
                    }
                ],
            ],
        ],
    ],
];

使用方法

编写简单消息

\Yii::error('message', 'category');

包含额外数据的消息

\Yii::warning([
    'msg' => 'message',
    'extra' => 'value',
], 'category');

标签

包含附加标签的消息。如果需要为事件添加附加标签,请在消息中添加 tags 键。标签是各种键/值对,它们会被分配给一个事件,并且可以在以后用作事件分解或快速查找相关事件的途径。

示例

\Yii::warning([
    'msg' => 'message',
    'extra' => 'value',
    'tags' => [
        'extraTagKey' => 'extraTagValue',
    ]
], 'category');

有关标签的更多信息,请参阅 https://docs.sentry.io/learn/context/#tagging-events

关于

notamedia/yii2-sentry 启发