Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support vendor handlers, processors and formatters. #3

Merged
merged 2 commits into from
Feb 13, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Lib/Log/Engine/MonologLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ private function __run($object, $name, $type, $params) {
$class = $name;
if (strpos($class, $type) === false) {
$class = "\Monolog\\$type\\$name$type";
} else if (isset($params['search'])) {
if (strpos($params['search'], '.php') === false) {
$params['search'] .= DS . $class . '.php';
}
include $params['search'];
unset($params['search']);
}

if ('Handler' === $type) {
Expand Down
51 changes: 51 additions & 0 deletions Lib/Log/Handler/CakeEmailHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
use Monolog\Logger;
use Monolog\Handler\MailHandler;

/**
* CakeEmailHandler uses CakeEmail to send the emails.
*
* Use it like so:
*
* CakeLog::config('web', array(
* 'engine' => 'Monolog.MonologLogger',
* 'channel' => 'web',
* 'handlers' => array(
* 'CakeEmailHandler' => array(
* "webmaster@domain.com",
* "ALERT: IMMEDIATE ACTION REQUIRED.",
* 'default',
* 'search' => CakePlugin::path('Monolog') . DS . 'Lib' . DS . 'Log' . DS . 'Handler'
* )
* )
*));
*
*/
class CakeEmailHandler extends \Monolog\Handler\MailHandler {

protected $_to;
protected $_subject;
protected $_config;

/**
* @param string|array $to The receiver of the mail
* @param string $subject The subject of the mail
* @param string $from The CakeEmail configuration to use
* @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($to, $subject, $config = 'default', $level = Logger::ERROR, $bubble = true) {
parent::__construct($level, $bubble);
$this->_to = $to;
$this->_subject = $subject;
$this->_config = $config;
}

/**
* {@inheritdoc}
*/
public function send($content, array $records) {
\CakeEmail::deliver($this->_to, $this->_subject, $content, $this->_config);
}

}