1. Go to this page and download the library: Download laxity7/yii2-sentry library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
Yii::warning([
// event name that will be sent to Sentry
'msg' => 'SomeWarning',
// extra data for the event
'data' => [
'userId' => Yii::$app->user->id,
'someDataOnWarningSituation' => $controller->state,
'modelThatCausedFailure' => $model->attributes,
],
], 'eventCategory');
use laxity7\sentry\Log;
// some code here
try {
$model->save();
} catch (\Exception $e) {
Log::warning([
// event name that will be sent to Sentry
'msg' => 'ExceptionWarning',
// extra data for the event
'data' => [
'userId' => Yii::$app->user->id,
'someDataOnWarningSituation' => $controller->state,
'modelThatCausedFailure' => $model->attributes,
],
], 'exceptionCategory', $e);
}
SentryHelper::extraData($task->attributes);
throw new Exception('unknown task type');
try {
throw new Exception('FAIL');
} catch (Exception $e) {
SentryHelper::captureWithMessage('Fail to save model', $e);
}
namespace common\components;
use Yii;
use yii\log\Logger;
use yii\helpers\Json;
class SyslogJsonTarget extends \yii\log\SyslogTarget
{
/**
* @inheritdoc
*/
public function formatMessage($message)
{
list($text, $level, $category, $timestamp) = $message;
$level = Logger::getLevelName($level);
if (!is_string($text)) {
$text = Json::encode($text);
} else {
$text = Json::encode(['rawstring' => $text]);
}
$prefix = $this->getMessagePrefix($message);
return "{$prefix}[$level][$category] $text";
}
}
php composer.phar
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.