rollbar-php icon indicating copy to clipboard operation
rollbar-php copied to clipboard

Respect exception context in RollbarLogger

Open rieschl opened this issue 6 years ago • 0 comments

When using the PSR-3 LoggerInterface implementation \Rollbar\RollbarLogger directly in a class to log certain exceptions, Rollbar doesn't respect the exception array key in the context parameter, the exception has to be passed as message to see the pretty stack trace in the Rollbar web interface.

Although technically this is ok, because PSR-3 states that Every method accepts a string as the message, or an object with a __toString() method. and the Exception (and Throwable) class has a __toString() method, it would be nice to also be able to pass the exception via the $context['exception'] key and use a string as $message. PSR-3 defines that behavior explicitly.

So the following code snippets should log the same thing in Rollbar:

/**
 * @var \Psr\Log\LoggerInterface $logger
 * @var \Throwable $e
 */
$logger->error($e); // current
$logger->error($e->getMessage(), ['exception' => $e]); // suggested

Thanks :)

rieschl avatar Jun 03 '19 07:06 rieschl