Robin Robin - 2 years ago 138
PHP Question

Overriding the log interface container binding lumen 5.0

I am trying to override where lumen writes logs, from 'storage/logs/lumen.log' to 'php://stderr'. The following code is what I am currently trying, and it does not work as expected.

No errors are thrown, and my logs are still written to the default location (in the storage/logs folder).

And when I do:


I get the default implementation.

Did I misinterpret the documentation, or am I approaching this the wrong way?

<?php namespace App\Providers;

use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Monolog\Formatter\LineFormatter;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
* Register any application services.
* @return void
public function register()
app()->instance('Psr\Log\LoggerInterface', new Logger('lumen', [$this->getMonologHandler()]));

public function getMonologHandler() {
return (new StreamHandler('php://stderr', Logger::DEBUG))->setFormatter(new LineFormatter(null, null, true, true));

Answer Source

You'll need to extend \Laravel\Lumen\Application and override the registerLogBindings() and/or getMonologHandler() method to set up your own logging config.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download