Skip to content

Conversation

Litarnus
Copy link
Contributor

@Litarnus Litarnus commented Aug 28, 2025

Introduces Sentry logging for Symfony.

Configuration works similar to the BreadcrumbHandler.

It's necessary to define the LogsHandler as a service like this:

services:
  Sentry\SentryBundle\Monolog\LogsHandler:
    arguments:
      - !php/const Monolog\Logger::INFO

and the register the handler in your monolog handler config:

monolog:
  handlers:
    sentry_logs:
      type: service
      id: Sentry\SentryBundle\Monolog\LogsHandler

and finally the option itself needs to be enabled:

sentry:
  options:
    enable_logs: true

This will end up in the docs very soon, but I wanted to provide this information here as well in case there are any concerns.

closes #925
closes SYMFONY-17

@Litarnus Litarnus self-assigned this Aug 28, 2025
* Sentry LogLevel objects are not easily usable with symfony config files, so this provides
* a convenient way to instantiate the service in yaml/xml.
*/
class LogsHandler extends BaseLogsHandler
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to go with inheritance here vs composition because I didn't want to write tests for all methods that are just forwarding.

@Litarnus Litarnus marked this pull request as ready for review August 28, 2025 15:42
@Litarnus Litarnus requested a review from cleptric August 28, 2025 15:42
Copy link

linear bot commented Aug 28, 2025

@cleptric cleptric enabled auto-merge (squash) September 1, 2025 09:10
@cleptric cleptric merged commit 9b169cc into master Sep 1, 2025
40 checks passed
@cleptric cleptric deleted the martinl/structured-logging branch September 1, 2025 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sentry Structured Logging for Symfony
2 participants