Last active
July 24, 2018 23:37
-
-
Save hissy/7aef3d2e47d491fc2658848e1b1d09e0 to your computer and use it in GitHub Desktop.
[concrete5] [v8]Add logging handler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** @var \Concrete\Core\Logging\Logger $logger */ | |
$logger = $app->make('log'); | |
$logger->pushHandler(new \Application\Logging\Handler\ConcreteMailerHandler( | |
'[email protected]', 'Error Notification', '[email protected]', \Concrete\Core\Logging\Logger::ERROR)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$classLoader = new \Symfony\Component\ClassLoader\Psr4ClassLoader(); | |
$classLoader->addPrefix('Application\\Logging', DIR_APPLICATION . '/' . DIRNAME_CLASSES . '/Logging'); | |
$classLoader->register(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Application\Logging\Handler; | |
use Concrete\Core\Logging\Logger; | |
use Concrete\Core\Mail\Service; | |
use Concrete\Core\Support\Facade\Application; | |
use Monolog\Handler\MailHandler; | |
class ConcreteMailerHandler extends MailHandler | |
{ | |
protected $to; | |
protected $subject; | |
protected $from; | |
public function __construct($to, $subject, $from, $level = Logger::ERROR, $bubble = true) | |
{ | |
parent::__construct($level, $bubble); | |
$this->to = is_array($to) ? $to : array($to); | |
$this->subject = $subject; | |
$this->from = $from; | |
} | |
/** | |
* @inheritDoc | |
*/ | |
protected function send($content, array $records) | |
{ | |
$app = Application::getFacadeApplication(); | |
/** @var Service $mh */ | |
$mh = $app->make('mail'); | |
foreach ($this->to as $to) { | |
$mh->to($to); | |
} | |
if ($this->subject) { | |
$mh->setSubject($this->subject); | |
} | |
if ($this->from) { | |
$mh->from($this->from); | |
} | |
$mh->setBody($content); | |
$mh->sendMail(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment