Hi,
I am using default laravel installation and calling \Log::error('error') does not send error message to the sentry. I can see this in the log file so it is working. If I throw an exception everything works as expected. Error is sent to the sentry and is logged to the file.
I am using sentry.io
laravel v5.2.43
sentry/sentry (1.5.0)
sentry/sentry-laravel (0.4.1)
Calling app('sentry')->captureMessage('bbbb'); works too.
@AidasK We don't automatically capture logging events as issues in Sentry. You could certainly configure a Monolog handler for it, but it's often noisy and incorrect. I'd suggest creating a "logError" abstraction which does both captureMessage (ideally captureException if you can have an error object) and Log::error.
Ended up using this in EventServiceProvider:
\Log::listen(function ($level, $message, $context) {
if ($level == 'debug') {
$level = 'info';
}
$context['level'] = $level;
if ($message instanceof \Exception) {
app('sentry')->captureException($message, [], $context);
} else {
app('sentry')->captureMessage($message, [], $context);
}
});
I'm still not opposed to having some kind of functionality like this in core (optional, see https://github.com/getsentry/sentry-laravel/pull/38). We havent had time to prioritize building it ourselves, but maybe a quick solution is to simply document how to do it yourself.
In case anyone's still wondering about this, Log facade and log() helper works with Sentry when you configure log channels on Laravel 5.6+. #38 won't be needed.
Most helpful comment
Ended up using this in EventServiceProvider: