sitmpcz / sentry-logger
Installs: 5 989
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.2
- sentry/sdk: >=3.1
README
Install
composer require sitmpcz/sentry-logger
Sentry event logger usage
-
run Sentry, register your project and get client DSN url
-
in config neon add in section parameters
sentry_url: https://something@abc.sentry.io/someproject
- in config neon add in section services
a) simple version
tracy.logger: Sitmpcz\SentryLogger(%sentry_url%)
b) extended version - use additional attributes (example with release attribute)
tracy.logger: create: Sitmpcz\SentryLogger(%sentry_url%) setup: - setAttribute('release', 'myApp@1.8.0') - setAttribute('environment', 'production')
Manual write to Sentry Error log
Using DI load Sentry Logger Example for presenter
/** @var \Sitmpcz\SentryLogger @inject */ public \Sitmpcz\SentryLogger $sentryLogger;
Then you can write error to Sentry manually:
$this->sentryLogger->log(new \Exception("test sentry"),\Tracy\ILogger::ERROR);
If you want to write to log manually, you can use Tracy\Debugger::log too, but you must specify higher priority (Napr CRITICAL) Example
\Tracy\Debugger::log("Test zapistu do logu",\Tracy\ILogger::CRITICAL);
Sentry performance usage (optional)
Example for Nette - BasePresenter:
private ?object $sentryPerformance = null; function startup(): void { parent::startup(); $this->sentryPerformance = Sitmpcz\SentryPerformance::startPerformaceMonitoring($this->getName(), $this->getAction()); } function shutdown(Nette\Application\Response $response): void { parent::shutdown($response); if ($this->sentryPerformance) Sitmpcz\SentryPerformance::endPerformaceMonitoring($this->sentryPerformance); }