I have installed the Rollbar 7.0 into Laravel 8.0. PHP version is 7.4 I am trying to send a test exception message using a simple Console command but that sends me nothing. My configs are the following: config/app.php:
return [ 'providers' => [ RollbarLaravelRollbarServiceProvider::class ... ]
config/logging.php:
'channels' => [ 'stack' => [ 'driver' => 'stack', 'channels' => ['other', 'rollbar'], 'ignore_exceptions' => false, ], 'rollbar' => [ 'driver' => 'monolog', 'handler' => MonologHandler::class, 'access_token' => env('ROLLBAR_TOKEN'), 'level' => env('ROLLBAR_LEVEL'), 'enabled' => true, 'environment' => env('ROLLBAR_ENVIRONMENT'), ] ....
config/services.php (but seems to be that it doesn’t work)
'rollbar' => [ 'access_token' => env('ROLLBAR_TOKEN'), 'environment' => env('ROLLBAR_ENVIRONMENT'), 'level' => env('ROLLBAR_LEVEL') ],
app.env:
ROLLBAR_TOKEN=real_token ROLLBAR_LEVEL=debug ROLLBAR_ENVIRONMENT=backend_test
And the console command itself has the following view:
public function handle() { // Rollbar::init([ // 'driver' => 'monolog', // 'handler' => MonologHandler::class, // 'access_token' => env('ROLLBAR_TOKEN'), // 'level' => env('ROLLBAR_LEVEL'), // 'enabled' => true, // 'environment' => env('ROLLBAR_ENVIRONMENT'), // ]); try{ $x = 4/0; } catch(Exception $exception) { Rollbar::error('caught demo exception', ["details" => $exception->getMessage()])); Rollbar::flush(); exit(1); } }
So when it is like this, the rollbar stays silent. But if I uncomment the initialisation, that works well, sending a debug message to the rollbar.
That doesn’t work all over the project too.
Could you please advice me, what could I do here in order to make it work globally with initialising in every file?
upd: I’ve also cleared config cache and tried to make a rollbar as a default
Advertisement
Answer
Laravel in app/logging.php has a default channel configuration. Normally “default” should mean that there are some other working channel too but here, somehow it the meaning is like “the only used channel”. Or I just do not fully understand how should it work. So my rollbar channel seems to be overriden by the another “default” one, that is why the system doesn’t use it. So the solution is to switch the default channel:
'default' => env('LOG_CHANNEL', 'stack'),
when the rollbar is included to stack channel or just
'default' => env('LOG_CHANNEL', 'rollbar'),
when it is not.