x2002uwh
9/9/2016 - 6:10 PM

Graylog2 UDP logger setup for symfony2 via monolog

Graylog2 UDP logger setup for symfony2 via monolog

Graylog 2 gelf installation

  • Add composer source: "graylog2/gelf-php": "~1.0"

Services Setup

parameters.yml

graylog.hostname: you.host.name
graylog.port: 12201
monolog.handler.gelf.debug_level: 100

#Log Level [100=>DEBUG, 200=>INFO, 300=>WARNING, 400=>ERROR, 500=>CRITICAL, 550=>ALERT]

services.yml

gelf.validator:
    class: Gelf\MessageValidator

gelf.transport:
    class: Gelf\Transport\UdpTransport
    arguments: [%graylog.hostname%, %graylog.port%]

gelf.publisher:
    class: Gelf\Publisher
    arguments: [@gelf.transport, @gelf.validator]

monolog.gelf_handler:
    class: Monolog\Handler\GelfHandler
    arguments: [@gelf.publisher, %monolog.handler.gelf.debug_level%]

Then setup you logger

gelf:
  type: service
  id: monolog.gelf_handler