1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-05 20:57:36 +02:00
This commit is contained in:
Gyula Sallai
2011-04-28 18:02:38 +02:00
parent a1bc483041
commit d87ba1c6e5
3 changed files with 26 additions and 2 deletions

View File

@@ -53,7 +53,9 @@ abstract class MailHandler extends AbstractHandler
$messages[] = $record['message'];
}
$this->send($this->createMessage($messages));
if (!empty($messages)) {
$this->send($this->createMessage($messages));
}
}
/**

View File

@@ -11,6 +11,8 @@
namespace Monolog\Handler;
use Monolog\Logger;
/**
* SwiftMailerHandler uses Swift_Mailer to send the emails
*
@@ -26,11 +28,15 @@ class SwiftMailerHandler extends MailHandler
* @param \Swift_Mailer $mailer The mailer to use
* @param \Swift_Message $message An example message for real messages,
* only the body will be replaced
* @param integer $level The minimum logging level at which this handler will be triggered
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
*/
public function __construct(\Swift_Mailer $mailer, \Swift_Message $message)
public function __construct(\Swift_Mailer $mailer, \Swift_Message $message, $level = Logger::ERROR, $bubble = false)
{
$this->mailer = $mailer;
$this->message = $message;
$this->level = $level;
$this->bubble = $bubble;
}
/**

View File

@@ -37,6 +37,22 @@ class MailHandlerTest extends TestCase
$handler->handleBatch($records);
}
public function testHandleBatchNotSendsMailIfMessagesAreBelowLevel()
{
$records = array(
$this->getRecord(Logger::DEBUG, 'debug message 1'),
$this->getRecord(Logger::DEBUG, 'debug message 2'),
$this->getRecord(Logger::INFO, 'information'),
);
$handler = $this->getMockForAbstractClass('Monolog\\Handler\\MailHandler');
$handler->expects($this->never())
->method('send');
$handler->setLevel(Logger::ERROR);
$handler->handleBatch($records);
}
public function testHandle()
{
$record = $this->getRecord();