public
Created — forked from Spea/deps

Gelf handler implementation for Symfony 2.0

  • Download Gist
config.yml
YAML
1 2 3 4 5 6 7 8 9
monolog:
handlers:
main:
type: stream
handler: gelf
level: WARNING
gelf:
type: service
id: monolog.gelf_handler
deps
1 2 3 4 5 6 7
[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
gelf.xml
XML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
<?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>
gistfile1.md
Markdown

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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.