xinningsu/thinkphp-rollbar

Rollbar integration for ThinkPHP, Rollbar整合ThinkPHP。

v1.0.0 2025-08-15 03:05 UTC

This package is auto-updated.

Last update: 2025-08-15 03:26:05 UTC


README

Rollbar integration for ThinkPHP, Rollbar整合ThinkPHP。

MIT licensed Build Status Code Coverage Scrutinizer Code Quality Code Intelligence Status

安装

composer require xinningsu/thinkphp-rollbar

配置

  1. 拷贝这个 配置文件config/rollbar.php, 请务必替换你的 access token。

    return [
        'access_token' => 'your_rollbar_access_token',
        // ...

    Rollbar的Access Token只在创建Project时出现一次,后续无法再找到。

    如果丢失,可以在 Project Settings > Project Access Tokens 新建一个。

    注意:页面中的 Public ID 并非 Access Token。

    其他配置项根据自己的需要修改。 更多配置项请参考: https://docs.rollbar.com/docs/php-configuration-reference

  2. 打开 app/ExceptionHandle.php,新增两行代码

    class ExceptionHandle extends Handle
    {
        // 1. 新增下面这行代码
        use \Sulao\ThinkRollbar\RollbarHandle;
    
        public function report(Throwable $exception): void
        {
            // 使用内置的方式记录异常日志
            parent::report($exception);
      
            // 2. 在 report 方法里新增下面这行代码
            $this->reportRollbar($exception);
        }
    }

测试

可以在controller中加入下面代码,然后看是否能在 Rollbar 上看到错误报告。

\Rollbar\Rollbar::log('error', new \Exception('test exception'));

License

MIT