sitmpcz / sentry-logger
此包最新版本(v1.6.1)没有提供许可信息。
v1.6.1
2024-02-26 11:45 UTC
Requires
- php: >=7.2
- sentry/sdk: >=3.1
README
安装
composer require sitmpcz/sentry-logger
Sentry事件日志器使用
-
运行Sentry,注册您的项目并获取客户端DSN URL
-
在neon配置中添加到参数部分
sentry_url: https://something@abc.sentry.io/someproject
- 在neon配置中添加到服务部分
a) 简单版本
tracy.logger: Sitmpcz\SentryLogger(%sentry_url%)
b) 扩展版本 - 使用额外的属性(例如使用发布属性)
tracy.logger: create: Sitmpcz\SentryLogger(%sentry_url%) setup: - setAttribute('release', 'myApp@1.8.0') - setAttribute('environment', 'production')
手动写入Sentry错误日志
使用DI加载Sentry日志器示例用于presenter
/** @var \Sitmpcz\SentryLogger @inject */ public \Sitmpcz\SentryLogger $sentryLogger;
然后您可以手动将错误写入Sentry
$this->sentryLogger->log(new \Exception("test sentry"),\Tracy\ILogger::ERROR);
如果您想手动写入日志,也可以使用Tracy\Debugger::log,但您必须指定更高的优先级(Napr CRITICAL)示例
\Tracy\Debugger::log("Test zapistu do logu",\Tracy\ILogger::CRITICAL);
Sentry性能使用(可选)
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); }