| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfWebDebugPanelLogs extends sfWebDebugPanel |
|---|
| 20 |
{ |
|---|
| 21 |
public function getTitle() |
|---|
| 22 |
{ |
|---|
| 23 |
return '<img src="'.$this->webDebug->getOption('image_root_path').'/log.png" alt="Log" /> logs'; |
|---|
| 24 |
} |
|---|
| 25 |
|
|---|
| 26 |
public function getPanelTitle() |
|---|
| 27 |
{ |
|---|
| 28 |
return 'Logs'; |
|---|
| 29 |
} |
|---|
| 30 |
|
|---|
| 31 |
public function getPanelContent() |
|---|
| 32 |
{ |
|---|
| 33 |
$event = $this->webDebug->getEventDispatcher()->filter(new sfEvent($this, 'debug.web.filter_logs'), $this->webDebug->getLogger()->getLogs()); |
|---|
| 34 |
$logs = $event->getReturnValue(); |
|---|
| 35 |
|
|---|
| 36 |
$html = '<table class="sfWebDebugLogs"> |
|---|
| 37 |
<tr> |
|---|
| 38 |
<th>#</th> |
|---|
| 39 |
<th>type</th> |
|---|
| 40 |
<th>message</th> |
|---|
| 41 |
</tr>'."\n"; |
|---|
| 42 |
$line_nb = 0; |
|---|
| 43 |
foreach ($logs as $log) |
|---|
| 44 |
{ |
|---|
| 45 |
$priority = $this->webDebug->getPriority($log['priority']); |
|---|
| 46 |
|
|---|
| 47 |
if (strpos($type = $log['type'], 'sf') === 0) |
|---|
| 48 |
{ |
|---|
| 49 |
$type = substr($type, 2); |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
$debug_info = ''; |
|---|
| 54 |
if (count($log['debug_stack'])) |
|---|
| 55 |
{ |
|---|
| 56 |
$debug_info .= ' <a href="#" onclick="sfWebDebugToggle(\'debug_'.$line_nb.'\'); return false;"><img src="'.$this->webDebug->getOption('image_root_path').'/toggle.gif" alt="Toggle XDebug details" /></a><div class="sfWebDebugDebugInfo" id="debug_'.$line_nb.'" style="display:none">'; |
|---|
| 57 |
foreach ($log['debug_stack'] as $i => $logLine) |
|---|
| 58 |
{ |
|---|
| 59 |
$debug_info .= '#'.$i.' » '.$this->formatLogLine($logLine).'<br/>'; |
|---|
| 60 |
} |
|---|
| 61 |
$debug_info .= "</div>\n"; |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
++$line_nb; |
|---|
| 65 |
$html .= sprintf("<tr class='sfWebDebugLogLine sfWebDebug%s %s'><td class=\"sfWebDebugLogNumber\">%s</td><td class=\"sfWebDebugLogType\">%s %s</td><td>%s%s</td></tr>\n", |
|---|
| 66 |
ucfirst($priority), |
|---|
| 67 |
$log['type'], |
|---|
| 68 |
$line_nb, |
|---|
| 69 |
'<img src="'.$this->webDebug->getOption('image_root_path').'/'.$priority.'.png" alt="'.ucfirst($priority).'"/>', |
|---|
| 70 |
$type, |
|---|
| 71 |
$this->formatLogLine($log['message']), |
|---|
| 72 |
$debug_info |
|---|
| 73 |
); |
|---|
| 74 |
} |
|---|
| 75 |
$html .= '</table>'; |
|---|
| 76 |
|
|---|
| 77 |
$types = array(); |
|---|
| 78 |
foreach ($this->webDebug->getLogger()->getTypes() as $type) |
|---|
| 79 |
{ |
|---|
| 80 |
$types[] = '<a href="#" onclick="sfWebDebugToggleMessages(\''.$type.'\'); return false;">'.$type.'</a>'; |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
return ' |
|---|
| 84 |
<ul id="sfWebDebugLogMenu"> |
|---|
| 85 |
<li><a href="#" onclick="sfWebDebugToggleAllLogLines(true, \'sfWebDebugLogLine\'); return false;">[all]</a></li> |
|---|
| 86 |
<li><a href="#" onclick="sfWebDebugToggleAllLogLines(false, \'sfWebDebugLogLine\'); return false;">[none]</a></li> |
|---|
| 87 |
<li><a href="#" onclick="sfWebDebugShowOnlyLogLines(\'info\'); return false;"><img src="'.$this->webDebug->getOption('image_root_path').'/info.png" alt="Show only infos" /></a></li> |
|---|
| 88 |
<li><a href="#" onclick="sfWebDebugShowOnlyLogLines(\'warning\'); return false;"><img src="'.$this->webDebug->getOption('image_root_path').'/warning.png" alt="Show only warnings" /></a></li> |
|---|
| 89 |
<li><a href="#" onclick="sfWebDebugShowOnlyLogLines(\'error\'); return false;"><img src="'.$this->webDebug->getOption('image_root_path').'/error.png" alt="Show only errors" /></a></li> |
|---|
| 90 |
<li>'.implode("</li>\n<li>", $types).'</li> |
|---|
| 91 |
</ul> |
|---|
| 92 |
<div id="sfWebDebugLogLines">'.$html.'</div> |
|---|
| 93 |
'; |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
* Formats a log line. |
|---|
| 98 |
* |
|---|
| 99 |
* @param string $logLine The log line to format |
|---|
| 100 |
* |
|---|
| 101 |
* @return string The formatted log lin |
|---|
| 102 |
*/ |
|---|
| 103 |
protected function formatLogLine($logLine) |
|---|
| 104 |
{ |
|---|
| 105 |
static $constants; |
|---|
| 106 |
|
|---|
| 107 |
if (!$constants) |
|---|
| 108 |
{ |
|---|
| 109 |
foreach (array('sf_app_dir', 'sf_root_dir', 'sf_symfony_lib_dir') as $constant) |
|---|
| 110 |
{ |
|---|
| 111 |
$constants[realpath(sfConfig::get($constant)).DIRECTORY_SEPARATOR] = $constant.DIRECTORY_SEPARATOR; |
|---|
| 112 |
} |
|---|
| 113 |
} |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
$logLine = htmlspecialchars($logLine, ENT_QUOTES, sfConfig::get('sf_charset')); |
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
$logLine = str_replace(array_keys($constants), array_values($constants), $logLine); |
|---|
| 120 |
|
|---|
| 121 |
$logLine = sfToolkit::pregtr($logLine, array('/"(.+?)"/s' => '"<span class="sfWebDebugLogInfo">\\1</span>"', |
|---|
| 122 |
'/^(.+?)\(\)\:/S' => '<span class="sfWebDebugLogInfo">\\1()</span>:', |
|---|
| 123 |
'/line (\d+)$/' => 'line <span class="sfWebDebugLogInfo">\\1</span>')); |
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
$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/', '<span class="sfWebDebugLogInfo">\\1</span>', $logLine); |
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
if (strpos($logLine, 'DSN') !== false) |
|---|
| 130 |
{ |
|---|
| 131 |
$logLine = preg_replace("/=>\s+'?[^'\s,]+'?/", "=> '****'", $logLine); |
|---|
| 132 |
} |
|---|
| 133 |
|
|---|
| 134 |
return $logLine; |
|---|
| 135 |
} |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|