Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hgfischer
Forked from Spea/deps
Created May 10, 2012 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hgfischer/2654837 to your computer and use it in GitHub Desktop.
Save hgfischer/2654837 to your computer and use it in GitHub Desktop.
Gelf handler implementation for Symfony 2.0
monolog:
handlers:
main:
type: stream
handler: gelf
level: WARNING
gelf:
type: service
id: monolog.gelf_handler
[monolog]
git=http://github.com/Seldaek/monolog.git
version=1.1.0
[gelf-php]
git=http://github.com/mlehner/gelf-php.git
version=v1.0
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="monolog.handler.gelf.class">Monolog\Handler\GelfHandler</parameter>
<parameter key="monolog.handler.gelf.debug_level">200</parameter> <!-- since we can not use strings here, we have to use the integer value of the debug levels, 200 is deubbing level INFO -->
<parameter key="gelf.publisher.class">Gelf\MessagePublisher</parameter>
<parameter key="graylog.hostname">localhost</parameter>
<parameter key="graylog.port">12201</parameter>
</parameters>
<services>
<service id="gelf.publisher" class="%gelf.publisher.class%">
<argument>%graylog.hostname%</argument>
<argument>%graylog.port%</argument>
</service>
<service id="monolog.gelf_handler" class="%monolog.handler.gelf.class%">
<argument type="service" id="gelf.publisher" />
<argument>%monolog.handler.gelf.debug_level%</argument>
</service>
</services>
</container>

Tying all together.

The gelf.xml should be placed in app/config and included in your config.yml:

imports:
    - { resource: gelf.xml }

Adjust the parameters to your needs (parameters.yml/parameters.ini):

parameters:
    graylog.hostname: graylog.example.com
    graylog.port: 12201
    
    # DEBUG
    # monolog.handler.gelf.debug_level: 100
    # INFO (default)
    monolog.handler.gelf.debug_level: 200
    # WARNING
    # monolog.handler.gelf.debug_level: 300
    # ERROR
    # monolog.handler.gelf.debug_level: 400
    # CRITICAL
    # monolog.handler.gelf.debug_level: 500
    # ALERT
    # monolog.handler.gelf.debug_level: 550
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment