Skip to content

Commit

Permalink
Make the channel for log mail driver configurable
Browse files Browse the repository at this point in the history
Allows users to specify the channel the log the emails when using the `log` driver.
  • Loading branch information
sebdesign committed Nov 14, 2018
1 parent 5d8508f commit 5ff17b4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Illuminate/Mail/TransportManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ protected function createSparkPostDriver()
*/
protected function createLogDriver()
{
return new LogTransport($this->app->make(LoggerInterface::class));
$channel = $this->app['config']['mail.log_channel'];

return new LogTransport(
$this->app->make(LoggerInterface::class)->channel($channel)
);
}

/**
Expand Down
50 changes: 50 additions & 0 deletions tests/Mail/MailLogTransportTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Illuminate\Tests\Mail;

use Monolog\Logger;
use Psr\Log\LoggerInterface;
use Orchestra\Testbench\TestCase;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\RotatingFileHandler;
use Illuminate\Mail\Transport\LogTransport;

class MailLogTransportTest extends TestCase
{
public function testGetLogTransportWithDefaultChannel()
{
$manager = $this->app['swift.transport'];

$transport = $manager->driver('log');
$this->assertInstanceOf(LogTransport::class, $transport);

$logger = $this->readAttribute($transport, 'logger');
$this->assertInstanceOf(LoggerInterface::class, $logger);

$this->assertInstanceOf(Logger::class, $monolog = $logger->getLogger());
$this->assertCount(1, $handlers = $monolog->getHandlers());
$this->assertInstanceOf(RotatingFileHandler::class, $handlers[0]);
}

public function testGetLogTransportWithConfiguredChannel()
{
$this->app['config']->set('mail.log_channel', 'mail');
$this->app['config']->set('logging.channels.mail', [
'driver' => 'single',
'path' => 'mail.log',
]);

$manager = $this->app['swift.transport'];

$transport = $manager->driver('log');
$this->assertInstanceOf(LogTransport::class, $transport);

$logger = $this->readAttribute($transport, 'logger');
$this->assertInstanceOf(LoggerInterface::class, $logger);

$this->assertInstanceOf(Logger::class, $monolog = $logger->getLogger());
$this->assertCount(1, $handlers = $monolog->getHandlers());
$this->assertInstanceOf(StreamHandler::class, $handler = $handlers[0]);
$this->assertEquals('mail.log', $handler->getUrl());
}
}

0 comments on commit 5ff17b4

Please sign in to comment.