* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * 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 12982 2008-11-13 17:25:10Z hartym $ */ class sfWebDebugPanelLogs extends sfWebDebugPanel { public function getTitle() { return 'Log logs'; } public function getPanelTitle() { return 'Logs'; } public function getPanelContent() { $event = $this->webDebug->getEventDispatcher()->filter(new sfEvent($this, 'debug.web.filter_logs'), $this->webDebug->getLogger()->getLogs()); $logs = $event->getReturnValue(); $html = ''."\n"; $line_nb = 0; foreach ($logs as $log) { $priority = $this->webDebug->getPriority($log['priority']); if (strpos($type = $log['type'], 'sf') === 0) { $type = substr($type, 2); } // xdebug information $debug_info = ''; if (count($log['debug_stack'])) { $debug_info .= ' Toggle XDebug details\n"; } ++$line_nb; $html .= sprintf("\n", ucfirst($priority), $log['type'], $line_nb, ''.ucfirst($priority).'', $type, $this->formatLogLine($log['message']), $debug_info ); } $html .= '
# type message
%s%s %s%s%s
'; $types = array(); foreach ($this->webDebug->getLogger()->getTypes() as $type) { $types[] = ''.$type.''; } return '
'.$html.'
'; } /** * Formats a log line. * * @param string $logLine The log line to format * * @return string The formatted log lin */ protected function formatLogLine($logLine) { static $constants; if (!$constants) { foreach (array('sf_app_dir', 'sf_root_dir', 'sf_symfony_lib_dir') as $constant) { $constants[realpath(sfConfig::get($constant)).DIRECTORY_SEPARATOR] = $constant.DIRECTORY_SEPARATOR; } } // escape HTML $logLine = htmlspecialchars($logLine, ENT_QUOTES, sfConfig::get('sf_charset')); // replace constants value with constant name $logLine = str_replace(array_keys($constants), array_values($constants), $logLine); $logLine = sfToolkit::pregtr($logLine, array('/"(.+?)"/s' => '"\\1"', '/^(.+?)\(\)\:/S' => '\\1():', '/line (\d+)$/' => 'line \\1')); // special formatting for SQL lines $logLine = preg_replace('/\b(SELECT|FROM|AS|LIMIT|ASC|COUNT|DESC|WHERE|LEFT JOIN|INNER JOIN|RIGHT JOIN|ORDER BY|GROUP BY|IN|LIKE|DISTINCT|DELETE|INSERT|INTO|VALUES)\b/', '\\1', $logLine); // remove username/password from DSN if (strpos($logLine, 'DSN') !== false) { $logLine = preg_replace("/=>\s+'?[^'\s,]+'?/", "=> '****'", $logLine); } return $logLine; } }