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’),
\Gelf\Transport\UdpTransport::CHUNK_SIZE_LAN);
$publisher = new \Gelf\Publisher();
$publisher->addTransport($transport);
$grayLogHandler = new \Monolog\Handler\GelfHandler($publisher);
$monolog->pushHandler($grayLogHandler);
...

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

<?php

namespace
App\Services;

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

class GraylogSetup
{
public function getGelfPublisher() : Publisher
{
$transport = new UdpTransport(config('graylog.host'), config('graylog.port'),
UdpTransport::CHUNK_SIZE_LAN);
$publisher = new Publisher();
$publisher->addTransport($transport);
return $publisher;
}
}

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

<?php

return
[
'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.