From 940ac808c9e316c259d2cde05a6989343529528b Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Mon, 13 May 2013 07:55:44 -0400 Subject: [PATCH] debugger tool WIP --- yii/logging/DebugTarget.php | 48 +++++++++++++++++++++++++++++++++++ yii/logging/Target.php | 15 +++++------ yii/logging/WebTarget.php | 61 --------------------------------------------- 3 files changed, 56 insertions(+), 68 deletions(-) create mode 100644 yii/logging/DebugTarget.php delete mode 100644 yii/logging/WebTarget.php diff --git a/yii/logging/DebugTarget.php b/yii/logging/DebugTarget.php new file mode 100644 index 0000000..3392d47 --- /dev/null +++ b/yii/logging/DebugTarget.php @@ -0,0 +1,48 @@ + + * @since 2.0 + */ +class DebugTarget extends Target +{ + /** + * Exports log messages to a specific destination. + * Child classes must implement this method. + * @param array $messages the messages to be exported. See [[Logger::messages]] for the structure + * of each message. + */ + public function export($messages) + { + } + + /** + * Processes the given log messages. + * This method will filter the given messages with [[levels]] and [[categories]]. + * And if requested, it will also export the filtering result to specific medium (e.g. email). + * @param array $messages log messages to be processed. See [[Logger::messages]] for the structure + * of each message. + * @param boolean $final whether this method is called at the end of the current application + */ + public function collect($messages, $final) + { + $this->messages = array_merge($this->messages, $this->filterMessages($messages)); + $count = count($this->messages); + if ($count > 0 && ($final || $this->exportInterval > 0 && $count >= $this->exportInterval)) { + if (($context = $this->getContextMessage()) !== '') { + $this->messages[] = array($context, Logger::LEVEL_INFO, 'application', YII_BEGIN_TIME); + } + $this->export($this->messages); + $this->messages = array(); + } + } +} diff --git a/yii/logging/Target.php b/yii/logging/Target.php index 311334d..45e784a 100644 --- a/yii/logging/Target.php +++ b/yii/logging/Target.php @@ -7,6 +7,7 @@ namespace yii\logging; +use yii\base\Component; use yii\base\InvalidConfigException; /** @@ -25,7 +26,7 @@ use yii\base\InvalidConfigException; * @author Qiang Xue * @since 2.0 */ -abstract class Target extends \yii\base\Component +abstract class Target extends Component { /** * @var boolean whether to enable this log target. Defaults to true. @@ -67,7 +68,7 @@ abstract class Target extends \yii\base\Component /** * @var array the messages that are retrieved from the logger so far by this log target. */ - private $_messages = array(); + public $messages = array(); private $_levels = 0; @@ -89,14 +90,14 @@ abstract class Target extends \yii\base\Component */ public function collect($messages, $final) { - $this->_messages = array_merge($this->_messages, $this->filterMessages($messages)); - $count = count($this->_messages); + $this->messages = array_merge($this->messages, $this->filterMessages($messages)); + $count = count($this->messages); if ($count > 0 && ($final || $this->exportInterval > 0 && $count >= $this->exportInterval)) { if (($context = $this->getContextMessage()) !== '') { - $this->_messages[] = array($context, Logger::LEVEL_INFO, 'application', YII_BEGIN_TIME); + $this->messages[] = array($context, Logger::LEVEL_INFO, 'application', YII_BEGIN_TIME); } - $this->export($this->_messages); - $this->_messages = array(); + $this->export($this->messages); + $this->messages = array(); } } diff --git a/yii/logging/WebTarget.php b/yii/logging/WebTarget.php deleted file mode 100644 index c98fd9f..0000000 --- a/yii/logging/WebTarget.php +++ /dev/null @@ -1,61 +0,0 @@ - - * @since 2.0 - */ -class CWebLogRoute extends CLogRoute -{ - /** - * @var boolean whether the log should be displayed in FireBug instead of browser window. Defaults to false. - */ - public $showInFireBug = false; - - /** - * @var boolean whether the log should be ignored in FireBug for ajax calls. Defaults to true. - * This option should be used carefully, because an ajax call returns all output as a result data. - * For example if the ajax call expects a json type result any output from the logger will cause ajax call to fail. - */ - public $ignoreAjaxInFireBug = true; - - /** - * Displays the log messages. - * @param array $logs list of log messages - */ - public function processLogs($logs) - { - $this->render('log', $logs); - } - - /** - * Renders the view. - * @param string $view the view name (file name without extension). The file is assumed to be located under framework/data/views. - * @param array $data data to be passed to the view - */ - protected function render($view, $data) - { - $app = \Yii::$app; - $isAjax = $app->getRequest()->getIsAjaxRequest(); - - if ($this->showInFireBug) - { - if ($isAjax && $this->ignoreAjaxInFireBug) - return; - $view .= '-firebug'; - } elseif (!($app instanceof CWebApplication) || $isAjax) - return; - - $viewFile = YII_PATH . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . $view . '.php'; - include($app->findLocalizedFile($viewFile, 'en')); - } -}