0
votes

In laravel 5.6 documentation it says You can use a different driver from the defaults when You create a log

Creating Monolog Handler Channels

So I tried the following in the config/logging.php file

'channels' => [
    'stack' => [
        'driver' => 'stack',
        'channels' => ['masterLog', 'daily'],
    ],
    'email' => [
        'driver'  => 'monolog',
        'handler' => Monolog\Handler\SwiftMailerHandler::class,
        'with'    => [
            'mailer' => Mail::to('[email protected]')->send(new App\Mail\TestMail()),
        ],
        'level' => 'debug',
    ],

I created my own email channel with the handler Monolog\Handler\SwiftMailerHandler::class and I noticed the class constructor recives a mailer object so I try this

Mail::to('[email protected]')->send(new App\Mail\TestMail())

but I get the following error

RuntimeException A facade root has not been set.

I'm testing the error by this way

 try {
        throw new Exception('Test Error');
    } catch (\Exception $e) {
        Log::stack(['datePayments', 'stack', 'email'])->emergency("user error", ['error' => $e, 'userID'=>Auth::id()]);
    }

So how can I configure this to make it works?

1

1 Answers

3
votes

Theres a package here https://github.com/designmynight/laravel-log-mailer that adds a mail driver to Laravel's LogManager which should do exactly what you are after.