Sentry logger for Yii2
composer require notamedia/yii2-sentry
Add target class in the application config:
return [
'components' => [
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'notamedia\sentry\SentryTarget',
'dsn' => 'http://2682ybvhbs347:[email protected]/1',
'levels' => ['error', 'warning'],
'context' => true // Write the context information. The default is true.
],
],
],
],
];
Writing simple message:
\Yii::error('message', 'category');
Writing messages with extra data:
\Yii::warning([
'msg' => message',
'extra' => 'value'
], 'category');
extraCallback
property can modify extra's data as callable function:
'targets' => [
[
'class' => 'notamedia\sentry\SentryTarget',
'dsn' => 'http://2682ybvhbs347:[email protected]/1',
'levels' => ['error', 'warning'],
'context' => true // Write the context information. The default is true.
'extraCallback' => function ($context, $extra) {
// some manipulation with data
$extra['some_data'] = \Yii::$app->someComponent->someMethod();
return $extra;
}
],
],
Yii2 log levels converts to Sentry levels:
\yii\log\Logger::LEVEL_ERROR => 'error',
\yii\log\Logger::LEVEL_WARNING => 'warning',
\yii\log\Logger::LEVEL_INFO => 'info',
\yii\log\Logger::LEVEL_TRACE => 'debug',
\yii\log\Logger::LEVEL_PROFILE_BEGIN => 'debug',
\yii\log\Logger::LEVEL_PROFILE_END => 'debug',