Skip to content

Commit

Permalink
Sentry ^2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
radimvaculik committed Aug 17, 2020
1 parent 0346ca7 commit 2522aa8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"ninjify/qa": "^0.9.0",
"ninjify/nunjuck": "^0.2.0",
"nette/di": "^3.0.0",
"sentry/sentry": "^1.9.2",
"sentry/sdk": "^2.1",
"phpstan/phpstan-deprecation-rules": "^0.11",
"phpstan/phpstan-nette": "^0.11",
"phpstan/phpstan-shim": "^0.11",
Expand All @@ -31,7 +31,7 @@
},
"suggest": {
"nette/di": "to use TracyLoggingExtension",
"sentry/sentry": "to use SentryLoggingExtension"
"sentry/sdk": "to use SentryLoggingExtension"
},
"autoload": {
"psr-4": {
Expand Down
35 changes: 16 additions & 19 deletions src/Sentry/SentryLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@

use Contributte\Logging\Exceptions\Logical\InvalidStateException;
use Contributte\Logging\ILogger;
use Raven_Client;
use Sentry\ClientBuilder;
use Sentry\Severity;
use Sentry\State\Scope;
use Throwable;

class SentryLogger implements ILogger
{

public const LEVEL_PRIORITY_MAP = [
self::DEBUG => Raven_Client::DEBUG,
self::INFO => Raven_Client::INFO,
self::WARNING => Raven_Client::WARNING,
self::ERROR => Raven_Client::ERROR,
self::EXCEPTION => Raven_Client::FATAL,
self::CRITICAL => Raven_Client::FATAL,
self::DEBUG => Severity::DEBUG,
self::INFO => Severity::INFO,
self::WARNING => Severity::WARNING,
self::ERROR => Severity::ERROR,
self::EXCEPTION => Severity::FATAL,
self::CRITICAL => Severity::FATAL,
];

public const CONFIG_URL = 'url';
Expand Down Expand Up @@ -69,28 +71,23 @@ public function log($message, string $priority = ILogger::INFO): void
return;
}

$data = [
'level' => $level,
];
$scope = (new Scope())->setLevel(new Severity($level));

$this->makeRequest($message, $data);
$this->makeRequest($message, $scope);
}

/**
* @param mixed $message
* @param mixed[] $data
*/
protected function makeRequest($message, array $data): void
protected function makeRequest($message, Scope $scope): void
{
$client = new Raven_Client(
$this->configuration[self::CONFIG_URL],
$this->configuration[self::CONFIG_OPTIONS]
);
$client = ClientBuilder::create($this->configuration[self::CONFIG_OPTIONS] + ['dsn' => $this->configuration[self::CONFIG_URL]])
->getClient();

if ($message instanceof Throwable) {
$client->captureException($message, $data);
$client->captureException($message, $scope);
} else {
$client->captureMessage($message, [], $data);
$client->captureMessage($message, null, $scope);
}
}

Expand Down

0 comments on commit 2522aa8

Please sign in to comment.