1: <?php
2: /**
3: * CWebLogRoute class file.
4: *
5: * @author Qiang Xue <qiang.xue@gmail.com>
6: * @link http://www.yiiframework.com/
7: * @copyright 2008-2013 Yii Software LLC
8: * @license http://www.yiiframework.com/license/
9: */
10:
11: /**
12: * CWebLogRoute shows the log content in Web page.
13: *
14: * The log content can appear either at the end of the current Web page
15: * or in FireBug console window (if {@link showInFireBug} is set true).
16: *
17: * @author Qiang Xue <qiang.xue@gmail.com>
18: * @package system.logging
19: * @since 1.0
20: */
21: class CWebLogRoute extends CLogRoute
22: {
23: /**
24: * @var boolean whether the log should be displayed in FireBug instead of browser window. Defaults to false.
25: */
26: public $showInFireBug=false;
27: /**
28: * @var boolean whether the log should be ignored in FireBug for ajax calls. Defaults to true.
29: * This option should be used carefully, because an ajax call returns all output as a result data.
30: * For example if the ajax call expects a json type result any output from the logger will cause ajax call to fail.
31: */
32: public $ignoreAjaxInFireBug=true;
33: /**
34: * @var boolean whether the log should be ignored in FireBug for Flash/Flex calls. Defaults to true.
35: * This option should be used carefully, because an Flash/Flex call returns all output as a result data.
36: * For example if the Flash/Flex call expects an XML type result any output from the logger will cause Flash/Flex call to fail.
37: * @since 1.1.11
38: */
39: public $ignoreFlashInFireBug=true;
40: /**
41: * @var boolean whether the log should be collapsed by default in Firebug. Defaults to false.
42: * @since 1.1.13.
43: */
44: public $collapsedInFireBug=false;
45:
46: /**
47: * Displays the log messages.
48: * @param array $logs list of log messages
49: */
50: public function processLogs($logs)
51: {
52: $this->render('log',$logs);
53: }
54:
55: /**
56: * Renders the view.
57: * @param string $view the view name (file name without extension). The file is assumed to be located under framework/data/views.
58: * @param array $data data to be passed to the view
59: */
60: protected function render($view,$data)
61: {
62: $app=Yii::app();
63: $isAjax=$app->getRequest()->getIsAjaxRequest();
64: $isFlash=$app->getRequest()->getIsFlashRequest();
65:
66: if($this->showInFireBug)
67: {
68: // do not output anything for ajax and/or flash requests if needed
69: if($isAjax && $this->ignoreAjaxInFireBug || $isFlash && $this->ignoreFlashInFireBug)
70: return;
71: $view.='-firebug';
72: if(($userAgent=$app->getRequest()->getUserAgent())!==null && preg_match('/msie [5-9]/i',$userAgent))
73: {
74: echo '<script type="text/javascript">';
75: echo file_get_contents(dirname(__FILE__).'/../vendors/console-normalizer/normalizeconsole.min.js');
76: echo "</script>\n";
77: }
78: }
79: elseif(!($app instanceof CWebApplication) || $isAjax || $isFlash)
80: return;
81:
82: $viewFile=YII_PATH.DIRECTORY_SEPARATOR.'views'.DIRECTORY_SEPARATOR.$view.'.php';
83: include($app->findLocalizedFile($viewFile,'en'));
84: }
85: }