xirkus's avatar

Lumen + papertrail

I've had Laravel integrated with papertrail using https://mattstauffer.co/blog/laravel-forge-logging-with-papertrail for a good while now. All good.

I've come to implement Matt's approach in Lumen and run into an issue. Lumen's Log facade is different to that in Laravel. It is directly linked with Monolog. So there is no Log::getMonolog() method.

I've tried a few approaches to resolving this - but I'm out of ideas. This is my current version (which is still stuffed in routes.php).

Any ideas?

$monolog = new \Monolog\Logger('lumen');
$syslog = new \Monolog\Handler\SyslogHandler('papertrail');
$formatter = new  \Monolog\Formatter\LineFormatter(null, null, false, true);
$syslog->setFormatter($formatter);
$monolog->pushHandler($syslog);
var_dump($monolog);
0 likes
3 replies
pzean's avatar

Have you come to a solution? I'm just facing the same problem.

ui-matt's avatar

Try something like this in bootstrap/app.php

$app->configureMonologUsing(function($monolog) {
    //configure here.
}
1 like
afrayedknot's avatar

This is the exact code that works for me:

$app->configureMonologUsing(function($monolog) {
    $syslog = new \Monolog\Handler\SyslogHandler('lumen');
    $formatter = new \Monolog\Formatter\LineFormatter(null, null, false, true);
    $syslog->setFormatter($formatter);
    $monolog->pushHandler($syslog);
    return $monolog;
});

Placed in bootstrap/app.php underneath the \\ $app->withFacades();

Please or to participate in this conversation.