When using the SentryBundle (Version 5.12.0) in a Symfony project, one might want to log the events it sends to Sentry. This is useful for debugging and monitoring. Here is how to enable it.
Configure the LogsHandler Service
All following definitions got to sentry.yaml file in your config/packages folder.
Define a LogsHandler service with the minimum log level you want to capture:
services:
Sentry\SentryBundle\Monolog\LogsHandler:
arguments:
- !php/const Monolog\Logger::WARNINGCode language: JavaScript (javascript)
Add the Handler to Monolog
Add the handler to the monolog configuration:
monolog:
handlers:
sentry:
type: service
id: Sentry\SentryBundle\Monolog\LogsHandler
Configure the Logger in Sentry
Add the main logger service to the SentryBundle configuration:
sentry:
logger: monolog.loggerCode language: CSS (css)
Enable Logging
Finally, enable logging in the SentryBundle configuration:
sentry:
logging:
enable_logs: trueCode language: JavaScript (javascript)
Result
Now, when an exception is captured by the SentryBundle, it will also be logged to the configured logger. For example:
Sent event [eaaf669ea6834546a20beb6ae0c5773f] to sentry.example.com [project:12]. Result: "success" (status: 200).Code language: CSS (css)
The Sentry documentation on Monolog integration is almost complete.
However, it misses the part where the logger service must be configured in the SentryBundle configuration.
Without it, the logger defaults to a `NullLogger`, and nothing gets logged.
Hope it helps.