Skip to content

Commit

Permalink
feature #10534 [SwiftMailer] [MonologBundle] send error log mails fro…
Browse files Browse the repository at this point in the history
…m CLI (arodiss)

This PR was merged into the 2.5-dev branch.

Discussion
----------

[SwiftMailer] [MonologBundle] send error log mails from CLI

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT

Given I have symfony2 application with Monolog configured to send mail on error logs.
When I have exception thrown from CLI task
Then I should receive error mail

However this is not true because `Monolog/SwiftMailerHandler` is doing force flush only on `kernel.terminate`, but not on `console.terminate`

This PR fixes issue together with symfony/monolog-bundle#73

Commits
-------

9bb602f added explicit swiftmailer flush after ConsoleEvents::TERMINATE
  • Loading branch information
fabpot committed Mar 26, 2014
2 parents 9dc14a5 + 9bb602f commit 790ba4c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Symfony/Bridge/Monolog/Handler/SwiftMailerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bridge\Monolog\Handler;

use Monolog\Handler\SwiftMailerHandler as BaseSwiftMailerHandler;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;

/**
Expand Down Expand Up @@ -43,6 +44,16 @@ public function onKernelTerminate(PostResponseEvent $event)
$this->instantFlush = true;
}

/**
* After the CLI application has been terminated we will always flush messages
*
* @param ConsoleTerminateEvent $event
*/
public function onCliTerminate(ConsoleTerminateEvent $event)
{
$this->instantFlush = true;
}

/**
* {@inheritdoc}
*/
Expand Down

0 comments on commit 790ba4c

Please sign in to comment.