Skip to content

asminog/yii2-sentry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sentry logger for Yii2

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

Installation

composer require asminog/yii2-sentry

Add target class in the application config:

return [
    'components' => [
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'asminog\yii2sentry\SentryTarget',
                    'levels' => ['error', 'warning'],
                    'dsn' => 'https://[email protected]/1',
//                    release option for project, default: 'auto'. Use "auto" to get it from git exec('git log --pretty="%H" -n1 HEAD')
                    'release' => '[email protected]',
//                    Options for sentry client
                    'options' => [],
//                    Collect additional context from $_GLOBALS, default: ['_SESSION', 'argv']. To switch off set [].
                    /* @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 [].
                    /* @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;
                    }
                ],
            ],
        ],
    ],
];

Usage

Writing simple message:

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

Writing messages with extra data:

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

Tags

Writing messages with additional tags. If need to add additional tags for event, add tags key in message. Tags are various key/value pairs that get assigned to an event, and can later be used as a breakdown or quick access to finding related events.

Example:

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

More about tags see https://docs.sentry.io/learn/context/#tagging-events

About

Inspired by notamedia/yii2-sentry

About

Yii2 logger for Sentry

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages