| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This file is part of the symfony package.
|
|
|
5 |
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
6 |
*
|
|
|
7 |
* For the full copyright and license information, please view the LICENSE
|
|
|
8 |
* file that was distributed with this source code.
|
|
|
9 |
*/
|
|
|
10 |
|
|
|
11 |
/**
|
|
|
12 |
* sfWebDebugPanelLogs adds a panel to the web debug toolbar with log messages.
|
|
|
13 |
*
|
|
|
14 |
* @package symfony
|
|
|
15 |
* @subpackage debug
|
|
|
16 |
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
17 |
* @version SVN: $Id: sfWebDebugPanelLogs.class.php 22182 2009-09-19 18:51:53Z Kris.Wallsmith $
|
|
|
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 |
// increase status
|
|
|
48 |
if ($log['priority'] < $this->getStatus())
|
|
|
49 |
{
|
|
|
50 |
$this->setStatus($log['priority']);
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
++$line_nb;
|
|
|
54 |
$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",
|
|
|
55 |
ucfirst($priority),
|
|
|
56 |
$log['type'],
|
|
|
57 |
$line_nb,
|
|
|
58 |
'<img src="'.$this->webDebug->getOption('image_root_path').'/'.$priority.'.png" alt="'.ucfirst($priority).'"/>',
|
|
|
59 |
class_exists($log['type'], false) ? $this->formatFileLink($log['type']) : $log['type'],
|
|
|
60 |
$this->formatLogLine($log['message']),
|
|
|
61 |
$this->getToggleableDebugStack($log['debug_backtrace'])
|
|
|
62 |
);
|
|
|
63 |
}
|
|
|
64 |
$html .= '</table>';
|
|
|
65 |
|
|
|
66 |
$types = array();
|
|
|
67 |
foreach ($this->webDebug->getLogger()->getTypes() as $type)
|
|
|
68 |
{
|
|
|
69 |
$types[] = '<a href="#" onclick="sfWebDebugToggleMessages(\''.$type.'\'); return false;">'.$type.'</a>';
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
return '
|
|
|
73 |
<ul id="sfWebDebugLogMenu">
|
|
|
74 |
<li><a href="#" onclick="sfWebDebugToggleAllLogLines(true, \'sfWebDebugLogLine\'); return false;">[all]</a></li>
|
|
|
75 |
<li><a href="#" onclick="sfWebDebugToggleAllLogLines(false, \'sfWebDebugLogLine\'); return false;">[none]</a></li>
|
|
|
76 |
<li><a href="#" onclick="sfWebDebugShowOnlyLogLines(\'info\'); return false;"><img src="'.$this->webDebug->getOption('image_root_path').'/info.png" alt="Show only infos" /></a></li>
|
|
|
77 |
<li><a href="#" onclick="sfWebDebugShowOnlyLogLines(\'warning\'); return false;"><img src="'.$this->webDebug->getOption('image_root_path').'/warning.png" alt="Show only warnings" /></a></li>
|
|
|
78 |
<li><a href="#" onclick="sfWebDebugShowOnlyLogLines(\'error\'); return false;"><img src="'.$this->webDebug->getOption('image_root_path').'/error.png" alt="Show only errors" /></a></li>
|
|
|
79 |
<li>'.implode("</li>\n<li>", $types).'</li>
|
|
|
80 |
</ul>
|
|
|
81 |
<div id="sfWebDebugLogLines">'.$html.'</div>
|
|
|
82 |
';
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
/**
|
|
|
86 |
* Formats a log line.
|
|
|
87 |
*
|
|
|
88 |
* @param string $logLine The log line to format
|
|
|
89 |
*
|
|
|
90 |
* @return string The formatted log lin
|
|
|
91 |
*/
|
|
|
92 |
protected function formatLogLine($logLine)
|
|
|
93 |
{
|
|
|
94 |
static $constants;
|
|
|
95 |
|
|
|
96 |
if (!$constants)
|
|
|
97 |
{
|
|
|
98 |
foreach (array('sf_app_dir', 'sf_root_dir', 'sf_symfony_lib_dir') as $constant)
|
|
|
99 |
{
|
|
|
100 |
$constants[realpath(sfConfig::get($constant)).DIRECTORY_SEPARATOR] = $constant.DIRECTORY_SEPARATOR;
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
// escape HTML
|
|
|
105 |
$logLine = htmlspecialchars($logLine, ENT_QUOTES, sfConfig::get('sf_charset'));
|
|
|
106 |
|
|
|
107 |
// replace constants value with constant name
|
|
|
108 |
$logLine = str_replace(array_keys($constants), array_values($constants), $logLine);
|
|
|
109 |
|
|
|
110 |
$logLine = sfToolkit::pregtr($logLine, array('/"(.+?)"/s' => '"<span class="sfWebDebugLogInfo">\\1</span>"',
|
|
|
111 |
'/^(.+?)\(\)\:/S' => '<span class="sfWebDebugLogInfo">\\1()</span>:',
|
|
|
112 |
'/line (\d+)$/' => 'line <span class="sfWebDebugLogInfo">\\1</span>'));
|
|
|
113 |
|
|
|
114 |
// special formatting for SQL lines
|
|
|
115 |
$logLine = $this->formatSql($logLine);
|
|
|
116 |
|
|
|
117 |
// remove username/password from DSN
|
|
|
118 |
if (strpos($logLine, 'DSN') !== false)
|
|
|
119 |
{
|
|
|
120 |
$logLine = preg_replace("/=>\s+'?[^'\s,]+'?/", "=> '****'", $logLine);
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
return $logLine;
|
|
|
124 |
}
|
|
|
125 |
}
|