1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-05 04:37:38 +02:00

Merge pull request #26 from stof/swiftmailer-callback

Added the possibility to configure the message using a callback in SwiftMailerHandler
This commit is contained in:
Jordi Boggiano
2011-05-08 09:37:45 -07:00
2 changed files with 13 additions and 7 deletions

View File

@@ -34,16 +34,16 @@ Notable Features (non-exhaustive and incomplete)
- _FingersCrossedHandler_: A very interesting handler. It takes a logger as parameter and will accumulate log records of all levels until a record exceeds the defined severity level. At which point it delivers all records, including those of lower severity, to the handler it wraps. This means that until an error actually happens you will not see anything in your logs, but when it happens you will have the full information, including debug and info records. This provides you with the info you need, only when you need it.
- _FirePHPHandler_: Handler for [FirePHP](http://www.firephp.org/), providing inline `console` messages within [FireBug](http://getfirebug.com/).
Todo
----
- MailHandler
Requirements
------------
Any flavor of PHP 5.3 should do
Submitting bugs and feature requests
------------------------------------
Bugs and feature request are tracked on [Github](https://github.com/Seldaek/monolog/issues)
Author
------

View File

@@ -25,14 +25,20 @@ 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 callback|\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, $level = Logger::ERROR, $bubble = false)
public function __construct(\Swift_Mailer $mailer, $message, $level = Logger::ERROR, $bubble = false)
{
parent::__construct($level, $bubble);
$this->mailer = $mailer;
if (!$message instanceof \Swift_Message && is_callable($message)) {
$message = call_user_func($message);
}
if (!$message instanceof \Swift_Message) {
throw new \InvalidArgumentException('You must provide either a Swift_Message instance or a callback returning it');
}
$this->message = $message;
}