How to use rollbar-php with Monolog

Monolog 1.x

Here is an example of how to use Rollbar as a handler for Monolog 1.x:


$logger = new Logger('ExampleMonologLogger');
$logger->pushHandler(new PsrHandler(Rollbar::logger()));
$logger->error(new \Exception("Example exception logged by Monolog."));

You can see a full example here:

Monolog 2.x

For Monolog 2, there is a dedicated handler included in the Monolog package:

use Monolog\Handler\RollbarHandler;

$log = new Logger('general');
$log->pushHandler(new RollbarHandler(Rollbar::logger()), Logger::DEBUG);


For more information on rollbar-php, please see the docs here.