Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 Monolog configure to use raven handler (Sentry)

I want to use sentry to evaluate possible errors, exceptions, etc.

I tried to use the KunstmaanSentryBundle and it's great to catch all kind of errors like undefined functions and so on, but I want to define my own Monolog channel with it's own handler, but unfortunately I haven't found documentation about it.

config.yml would be something like:

monolog:
  handlers:
    sentry:
        type:  stream
        level: error
        //Log to database parameter (raven for sentry)

Does anybody knows the right configuration?

like image 823
felipep Avatar asked Jan 14 '14 13:01

felipep


2 Answers

This is part of config_prod.yml:

monolog:
    handlers:
        main:
            type:         fingers_crossed
            action_level: error
            handler:      grouped_main

        sentry:
            type:  raven
            dsn:   'http://user:pass@url/1'
            level: notice

        # Groups
        grouped_main:
            type:    group
            members: [sentry, streamed_main]

        # Streams
        streamed_main:
            type:  stream
            path:  %kernel.logs_dir%/%kernel.environment%.log
            level: error

Enjoy! :)

like image 118
Anton Babenko Avatar answered Nov 07 '22 23:11

Anton Babenko


Wanted to add this as a comment on the accepted answer, but not enough rep, so:

From \Symfony\Bundle\MonologBundle\DependencyInjection\Configuration :

"Possible handler types and related configurations (brackets indicate optional params):

  • raven:
    • dsn: connection string
    • client_id: Raven client custom service id (optional)
    • [level]: level name or int value, defaults to DEBUG
    • [bubble]: bool, defaults to true

"

Example config would be:

monolog:
    handlers:
        sentry:
            type: raven
            dsn: '%sentry_api_key%'
            client_id: 'your.raven.client.custom.service.id'
            level: notice
            bubble: false
like image 5
gtb Avatar answered Nov 07 '22 22:11

gtb