Monolog
Learn how to enable Sentry's Symfony SDK to capture Monolog events.
Monolog logs can be captured as Sentry Logs for better searchability and querying.
To enable this, set enable_logs to true in your Sentry configuration:
config/packages/sentry.yamlCopied
sentry:
options:
enable_logs: true
Then configure the Monolog handler for logs:
config/packages/monolog.yamlCopied
services:
Sentry\SentryBundle\Monolog\LogsHandler:
arguments:
- !php/const Monolog\Logger::WARNING
monolog:
handlers:
sentry_logs:
type: service
id: Sentry\SentryBundle\Monolog\LogsHandler
You can control which log levels are sent to Sentry Logs by configuring the handler's minimum level in your services configuration.
When using Monolog you can configure a breadcrumb handler to capture Monolog messages as breadcrumbs and a handler that captures messages as events in Sentry. The breadcrumb handler will not send anything to Sentry directly, it only records breadcrumbs that will be attached to any event or exception sent to Sentry.
config/packages/sentry.yamlCopied
sentry:
register_error_listener: false # Disables the ErrorListener to avoid duplicated log in sentry
register_error_handler: false # Disables the ErrorListener, ExceptionListener and FatalErrorListener integrations of the base PHP SDK
services:
# (Optionally) Configure the breadcrumb handler as a service (needed for the breadcrumb Monolog handler)
Sentry\Monolog\BreadcrumbHandler:
arguments:
- '@Sentry\State\HubInterface'
- !php/const Monolog\Logger::INFO # Configures the level of messages to capture as breadcrumbs
Sentry\Monolog\Handler:
arguments:
$hub: '@Sentry\State\HubInterface'
$level: !php/const Monolog\Logger::ERROR
$fillExtraContext: true
monolog:
handlers:
# (Optionally) Register the breadcrumb handler as a Monolog handler
sentry_breadcrumbs:
type: service
name: sentry_breadcrumbs
id: Sentry\Monolog\BreadcrumbHandler
# Register the handler as a Monolog handler to capture messages as events
sentry:
type: service
id: Sentry\Monolog\Handler
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").