Setup Graylog in Laravel 5.6 logging

I am in love with new the Laravel logging configuration. The most basic cases are covered in the Laravel documentation, but if you want to send logs to Graylog instance, you have to configurate Monolog GelfHandler handler. It requires extra configuration.

Laravel 5.5

file bootstrap/app.php

$app->configureMonologUsing(function ($monolog) {
$transport = new \Gelf\Transport\UdpTransport(env(‘GRAYLOG_HOST’), env(‘GRAYLOG_PORT’),
$publisher = new \Gelf\Publisher();
$grayLogHandler = new \Monolog\Handler\GelfHandler($publisher);

Laravel 5.6 Logging configuration

file config/logging.php

'graylog' => [
'driver' => 'monolog',
'handler' => Monolog\Handler\GelfHandler::class,
'handler_with' => [
'publisher' => app(\App\Services\GraylogSetup::class)->getGelfPublisher(),
'formatter' => \Monolog\Formatter\GelfMessageFormatter::class

file Services/GraylogSetup.php



use Gelf\Publisher;
use Gelf\Transport\UdpTransport;

class GraylogSetup
public function getGelfPublisher() : Publisher
$transport = new UdpTransport(config(''), config('graylog.port'),
$publisher = new Publisher();
return $publisher;

file config/graylog.php contains Graylog host and port configuration


'host' => env('GRAYLOG_HOST'),
'port' => env('GRAYLOG_PORT'),

Currently, I did not think of any cleaner solution than this. I tried to do it with ServiceProvider bind and singleton but without any success.

If you like it give a clap. And if you have better solution, please provide it in the comments below.