[+] подключение сентри и новый метод логирования
This commit is contained in:
1 parent
295eca8f8a
commit
b55f76ade5
7 files changed
+1983
-4
No files matched your search
@@ -10,6 +10,29 @@
|
||||
session_start();
|
||||
}
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
\Sentry\init(
|
||||
[
|
||||
'dsn' => 'https://8657ac1a900c44e5bc51714bb4c00dbb@o1303100.ingest.sentry.io/6541634',
|
||||
'error_types' => E_ALL,
|
||||
]
|
||||
);
|
||||
|
||||
Sentry\configureScope(function (Sentry\State\Scope $sentryScope) {
|
||||
$sentryScope->setExtra('user_id', $_SESSION['id']);
|
||||
$sentryScope->setExtra('user_login', $_SESSION['login']);
|
||||
$sentryScope->setExtra('user_token', $_SESSION['token']);
|
||||
});
|
||||
/*
|
||||
try {
|
||||
$this->functionFailsForSure();
|
||||
} catch (\Throwable $exception) {
|
||||
\Sentry\captureException($exception);
|
||||
}
|
||||
|
||||
// OR
|
||||
|
||||
\Sentry\captureLastError();
|
||||
*/
|
||||
|
||||
|
||||
ob_start(function ($buffer) {
|
||||
|
||||
@@ -116,4 +116,38 @@
|
||||
|
||||
return $result ?: 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Метод сохранения логов в Sentry
|
||||
*
|
||||
* @param string $sentryMessage Сообщение, передаваемое в Sentry и отображающееся как заголовок Issue
|
||||
* @param string $sentryErrorLevel Уровень события Sentry (FATAL, ERROR, WARNING, INFO, DEBUG)
|
||||
* @param array $sentryData Массив данных лога
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function logToSentry(
|
||||
string $sentryMessage,
|
||||
string $sentryErrorLevel = 'DEBUG',
|
||||
array $sentryData = []
|
||||
): bool {
|
||||
$sentryErrorLevelArray = ['FATAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG'];
|
||||
|
||||
if (empty(trim($sentryMessage))
|
||||
|| !in_array($sentryErrorLevel, $sentryErrorLevelArray)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_array($sentryData) && count($sentryData) > 0) {
|
||||
\Sentry\configureScope(function (\Sentry\State\Scope $sentryScope) use ($sentryData) {
|
||||
foreach ($sentryData as $paramName => $paramValue) {
|
||||
$sentryScope->setExtra($paramName, $paramValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
\Sentry\captureMessage($sentryMessage, \Sentry\Severity::$sentryErrorLevel());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user