CWebLogRoute.php 2.8 KB

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