1. sfWebDebugPanelLogs.class.php
  2. /** * sfWebDebugPanelLogs adds a panel to the web debug toolbar with log messages. * * @package symfony * @subpackage debug * @author Fabien Potencier * @version SVN: $Id: sfWebDebugPanelLogs.class.php 22182 2009-09-19 18:51:53Z Kris.Wallsmith $ */
  3. class sfWebDebugPanelLogs extends sfWebDebugPanel
  4. {
  5. public function getTitle()
  6. {
  7. return '<img src="'.$this->webDebug->getOption('image_root_path').'/log.png" alt="Log" /> logs';
  8. }
  9. public function getPanelTitle()
  10. {
  11. return 'Logs';
  12. }
  13. public function getPanelContent()
  14. {
  15. $event = $this->webDebug->getEventDispatcher()->filter(new sfEvent($this, 'debug.web.filter_logs'), $this->webDebug->getLogger()->getLogs());
  16. $logs = $event->getReturnValue();
  17. $html = '<table class="sfWebDebugLogs">
  18. <tr>
  19. <th>#</th>
  20. <th>type</th>
  21. <th>message</th>
  22. </tr>'."\n";
  23. $line_nb = 0;
  24. foreach ($logs as $log)
  25. {
  26. $priority = $this->webDebug->getPriority($log['priority']);
  27. // increase status
  28. if ($log['priority'] < $this->getStatus())
  29. {
  30. $this->setStatus($log['priority']);
  31. }
  32. ++$line_nb;
  33. $html .= sprintf("<tr class='sfWebDebugLogLine sfWebDebug%s %s'><td class=\"sfWebDebugLogNumber\">%s</td><td class=\"sfWebDebugLogType\">%s&nbsp;%s</td><td>%s %s</td></tr>\n",
  34. ucfirst($priority),
  35. $log['type'],
  36. $line_nb,
  37. '<img src="'.$this->webDebug->getOption('image_root_path').'/'.$priority.'.png" alt="'.ucfirst($priority).'"/>',
  38. class_exists($log['type'], false) ? $this->formatFileLink($log['type']) : $log['type'],
  39. $this->formatLogLine($log['message']),
  40. $this->getToggleableDebugStack($log['debug_backtrace'])
  41. );
  42. }
  43. $html .= '</table>';
  44. $types = array();
  45. foreach ($this->webDebug->getLogger()->getTypes() as $type)
  46. {
  47. $types[] = '<a href="#" onclick="sfWebDebugToggleMessages(\''.$type.'\'); return false;">'.$type.'</a>';
  48. }
  49. return '
  50. <ul id="sfWebDebugLogMenu">
  51. <li><a href="#" onclick="sfWebDebugToggleAllLogLines(true, \'sfWebDebugLogLine\'); return false;">[all]</a></li>
  52. <li><a href="#" onclick="sfWebDebugToggleAllLogLines(false, \'sfWebDebugLogLine\'); return false;">[none]</a></li>
  53. <li><a href="#" onclick="sfWebDebugShowOnlyLogLines(\'info\'); return false;"><img src="'.$this->webDebug->getOption('image_root_path').'/info.png" alt="Show only infos" /></a></li>
  54. <li><a href="#" onclick="sfWebDebugShowOnlyLogLines(\'warning\'); return false;"><img src="'.$this->webDebug->getOption('image_root_path').'/warning.png" alt="Show only warnings" /></a></li>
  55. <li><a href="#" onclick="sfWebDebugShowOnlyLogLines(\'error\'); return false;"><img src="'.$this->webDebug->getOption('image_root_path').'/error.png" alt="Show only errors" /></a></li>
  56. <li>'.implode("</li>\n<li>", $types).'</li>
  57. </ul>
  58. <div id="sfWebDebugLogLines">'.$html.'</div>
  59. ';
  60. }
  61. /**
  62. * Formats a log line.
  63. *
  64. * @param string $logLine The log line to format
  65. *
  66. * @return string The formatted log lin
  67. */
  68. protected function formatLogLine($logLine)
  69. {
  70. static $constants;
  71. if (!$constants)
  72. {
  73. foreach (array('sf_app_dir', 'sf_root_dir', 'sf_symfony_lib_dir') as $constant)
  74. {
  75. $constants[realpath(sfConfig::get($constant)).DIRECTORY_SEPARATOR] = $constant.DIRECTORY_SEPARATOR;
  76. }
  77. }
  78. // escape HTML
  79. $logLine = htmlspecialchars($logLine, ENT_QUOTES, sfConfig::get('sf_charset'));
  80. // replace constants value with constant name
  81. $logLine = str_replace(array_keys($constants), array_values($constants), $logLine);
  82. $logLine = sfToolkit::pregtr($logLine, array('/&quot;(.+?)&quot;/s' => '"<span class="sfWebDebugLogInfo">\\1</span>"',
  83. '/^(.+?)\(\)\:/S' => '<span class="sfWebDebugLogInfo">\\1()</span>:',
  84. '/line (\d+)$/' => 'line <span class="sfWebDebugLogInfo">\\1</span>'));
  85. // special formatting for SQL lines
  86. $logLine = $this->formatSql($logLine);
  87. // remove username/password from DSN
  88. if (strpos($logLine, 'DSN') !== false)
  89. {
  90. $logLine = preg_replace("/=&gt;\s+'?[^'\s,]+'?/", "=&gt; '****'", $logLine);
  91. }
  92. return $logLine;
  93. }
  94. }

Debug toolbar