dlin/sentry-bundle

Sentry 的 Symfony 2 扩展包,使用 "raven-php" 客户端

0.9 2013-10-10 03:00 UTC

This package is not auto-updated.

Last update: 2024-09-23 15:51:11 UTC


README

Dlin Sentry Bundle 是 'raven-php' 库的 Symfony2 包装扩展包

此 Sentry 扩展包提供了一个可配置的服务,用于与 Sentry 交互

版本

0.9

安装

使用 Composer 进行安装

在您的 composer.json 中添加

json
{
    "require" :  {
        "dlin/sentry-bundle": "dev-master"
    }
}

在 AppKernel.php 中启用此扩展包

public function registerBundles()
{
    $bundles = array(
    ...
    new Dlin\Bundle\SentryBundle\DlinSentryBundle(),
    ...
}

配置

在 config.xml 文件中必须提供 DSN URL。例如

#app/config/config.yml

dlin_sentry:
    dsn: https://xxxxxxxxxxce4168aaafe6f658375edf:xxxxxxxxxxd44828a5ba7b78d807f5d@app.getsentry.com/123456

使用方法

在控制器中获取服务

$service =  $this->get('dlin.sentry_service');

在 ContainerAwareService 中获取服务

$service = $this->container->get('dlin.sentry_service');

手动向 Sentry 发送消息

$service->captureMessage('An error is found when user clicks the button');

手动向 Sentry 报告异常

try{
  throw new \Exception('hello, here is an exception');
}catch(\Exception $e){
    $optionalData = array();
    $optionalData['phpVersion'] = '5.3';
    $service->captureException($e, $optionalData);
}

自动向 Sentry 报告错误。

#web/app.php
...
$kernel->loadClassCache();

$kernel->boot();
$kernel->getContainer()->get('dlin.sentry_service')->register();
...

许可证

MIT

自由软件,太棒了!