Search code examples
phplaravellaravel-5monolog

Laravel: multiple log providers using `configureMonologUsing()`?


I'm using configureMonologUsing() to add in two custom loggers. Doing the standard SOLID principal, I have two providers: ConsoleLoggerProvider and MailLogProvider.

Both of these have a register similar to:

public function register()
{
    app()->configureMonologUsing(function(\Monolog\Logger $monolog) {
        $monolog->pushHandler(new HandlerClass());
    });
}

However, I have noticed over logger will overwrite another logger... How do I stack these?

I've tried to use boot() as well, and that didn't work. I couldn't find any other way to add to the Monolog stack.

Preferable, I want to stack onto Laravel's built-in logger as well.


Solution

  • I (finally) found the answer my question:

    Within my providers, instead of using configureMonologUsing(), I used Log::getMonolog()->pushHandler([..])

    That works! All loggers, including built-in Laravel file logger, are firing. Finally!

    (I've honestly been looking for days for a way to add onto the Monolog stack; I apparently wasn't searching by the right terms)