Skip to content

Commit 3873ec7

Browse files
[HttpKernel] Use VarDumper in the "Logs" panel of the profiler
1 parent f5b304e commit 3873ec7

File tree

6 files changed

+119
-186
lines changed

6 files changed

+119
-186
lines changed

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig

Lines changed: 45 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
{% import _self as helper %}
44

55
{% block toolbar %}
6-
{% if collector.counterrors or collector.countdeprecations or collector.countscreams %}
6+
{% if collector.counterrors or collector.countdeprecations or collector.countwarnings %}
77
{% set icon %}
8-
{% set status_color = collector.counterrors ? 'red' : collector.countdeprecations ? 'yellow' : '' %}
9-
{% set error_count = collector.counterrors + collector.countdeprecations %}
8+
{% set status_color = collector.counterrors ? 'red' : 'yellow' %}
109
{{ include('@WebProfiler/Icon/logger.svg') }}
11-
<span class="sf-toolbar-value">{{ error_count }}</span>
10+
<span class="sf-toolbar-value">{{ collector.counterrors ?: (collector.countdeprecations + collector.countwarnings) }}</span>
1211
{% endset %}
1312

1413
{% set text %}
@@ -18,13 +17,13 @@
1817
</div>
1918

2019
<div class="sf-toolbar-info-piece">
21-
<b>Deprecated Calls</b>
22-
<span class="sf-toolbar-status sf-toolbar-status-{{ collector.countdeprecations ? 'yellow' }}">{{ collector.countdeprecations|default(0) }}</span>
20+
<b>Warnings</b>
21+
<span class="sf-toolbar-status sf-toolbar-status-{{ collector.countwarnings ? 'yellow' }}">{{ collector.countwarnings|default(0) }}</span>
2322
</div>
2423

2524
<div class="sf-toolbar-info-piece">
26-
<b>Silenced Errors</b>
27-
<span class="sf-toolbar-status">{{ collector.countscreams|default(0) }}</span>
25+
<b>Deprecations</b>
26+
<span class="sf-toolbar-status sf-toolbar-status-{{ collector.countdeprecations ? 'yellow' }}">{{ collector.countdeprecations|default(0) }}</span>
2827
</div>
2928
{% endset %}
3029

@@ -33,12 +32,12 @@
3332
{% endblock %}
3433

3534
{% block menu %}
36-
<span class="label label-status-{{ collector.counterrors ? 'error' : collector.countdeprecations ? 'warning' }} {{ collector.logs is empty ? 'disabled' }}">
35+
<span class="label label-status-{{ collector.counterrors ? 'error' : collector.countdeprecations or collector.countwarnings ? 'warning' }} {{ collector.logs is empty ? 'disabled' }}">
3736
<span class="icon">{{ include('@WebProfiler/Icon/logger.svg') }}</span>
3837
<strong>Logs</strong>
39-
{% if collector.counterrors or collector.countdeprecations %}
38+
{% if collector.counterrors or collector.countdeprecations or collector.countwarnings %}
4039
<span class="count">
41-
<span>{{ collector.counterrors ?: collector.countdeprecations }}</span>
40+
<span>{{ collector.counterrors ?: (collector.countdeprecations + collector.countwarnings) }}</span>
4241
</span>
4342
{% endif %}
4443
</span>
@@ -55,9 +54,9 @@
5554
{# sort collected logs in groups #}
5655
{% set deprecation_logs, debug_logs, info_and_error_logs, silenced_logs = [], [], [], [] %}
5756
{% for log in collector.logs %}
58-
{% if log.context.errorCount is defined and log.context.type is defined and log.context.type in ['E_DEPRECATED', 'E_USER_DEPRECATED'] %}
57+
{% if log.scream is defined and not log.scream %}
5958
{% set deprecation_logs = deprecation_logs|merge([log]) %}
60-
{% elseif log.context.scream is defined and log.context.scream == true %}
59+
{% elseif log.scream is defined and log.scream %}
6160
{% set silenced_logs = silenced_logs|merge([log]) %}
6261
{% elseif log.priorityName == 'DEBUG' %}
6362
{% set debug_logs = debug_logs|merge([log]) %}
@@ -68,7 +67,7 @@
6867

6968
<div class="sf-tabs">
7069
<div class="tab">
71-
<h3 class="tab-title">Info. &amp; Errors <span class="badge">{{ info_and_error_logs|length }}</span></h3>
70+
<h3 class="tab-title">Info. &amp; Errors <span class="badge status-{{ collector.counterrors ? 'error' : collector.countwarnings ? 'warning' }}">{{ collector.counterrors ?: info_and_error_logs|length }}</span></h3>
7271

7372
<div class="tab-content">
7473
{% if info_and_error_logs is empty %}
@@ -84,7 +83,7 @@
8483
<div class="tab">
8584
{# 'deprecation_logs|length' is not used because deprecations are
8685
now grouped and the group count doesn't match the message count #}
87-
<h3 class="tab-title">Deprecations <span class="badge">{{ collector.countdeprecations|default(0) }}</span></h3>
86+
<h3 class="tab-title">Deprecations <span class="badge status-{{ collector.countdeprecations ? 'warning' }}">{{ collector.countdeprecations|default(0) }}</span></h3>
8887

8988
<div class="tab-content">
9089
{% if deprecation_logs is empty %}
@@ -112,7 +111,7 @@
112111
</div>
113112

114113
<div class="tab">
115-
<h3 class="tab-title">Silenced Errors <span class="badge">{{ collector.countscreams|default(0) }}</span></h3>
114+
<h3 class="tab-title">Silenced PHP Notices<span class="badge">{{ collector.countscreams|default(0) }}</span></h3>
116115

117116
<div class="tab-content">
118117
{% if silenced_logs is empty %}
@@ -138,26 +137,32 @@
138137
<tr>
139138
<th>{{ show_level ? 'Level' : 'Time' }}</th>
140139
{% if channel_is_defined %}<th>Channel</th>{% endif %}
141-
<th>Message</th>
140+
<th class="full-width">Message</th>
142141
</tr>
143142
</thead>
144143

145144
<tbody>
146145
{% for log in logs %}
147146
{% set css_class = is_deprecation ? ''
148147
: log.priorityName in ['CRITICAL', 'ERROR', 'ALERT', 'EMERGENCY'] ? 'status-error'
149-
: log.priorityName in ['NOTICE', 'WARNING'] ? 'status-warning'
148+
: log.priorityName == 'WARNING' ? 'status-warning'
150149
%}
151150
<tr class="{{ css_class }}">
152-
<td class="font-normal text-small">
151+
<td class="font-normal text-small" nowrap>
153152
{% if show_level %}
154-
<span class="colored text-bold nowrap">{{ log.priorityName }}</span>
153+
<span class="colored text-bold">{{ log.priorityName }}</span>
155154
{% endif %}
156-
<span class="text-muted nowrap newline">{{ log.timestamp|date('H:i:s') }}</span>
155+
<span class="text-muted newline">{{ log.timestamp|date('H:i:s') }}</span>
157156
</td>
158157

159158
{% if channel_is_defined %}
160-
<td class="font-normal text-small text-bold nowrap">{{ log.channel }}</td>
159+
<td class="font-normal text-small text-bold" nowrap>
160+
{{ log.channel }}
161+
{% if log.errorCount is defined and log.errorCount > 1 %}
162+
<span class="text-muted">({{ log.errorCount }} times)</span>
163+
{% endif %}
164+
</td>
165+
161166
{% endif %}
162167

163168
<td class="font-normal">{{ helper.render_log_message(category, loop.index, log, is_deprecation) }}</td>
@@ -168,69 +173,31 @@
168173
{% endmacro %}
169174

170175
{% macro render_log_message(category, log_index, log, is_deprecation = false) %}
171-
{{ log.message }}
172-
173-
{% if log.context.errorCount is defined and log.context.errorCount > 1 %}
174-
<span class="text-small text-bold">({{ log.context.errorCount }} times)</span>
175-
{% endif %}
176-
177176
{% if is_deprecation %}
178-
{% set trace = log.context.trace|default([]) %}
179-
{% set trace_id = 'sf-call-trace-' ~ category ~ '-' ~ log_index %}
177+
{{ log.message }}
180178

179+
{% set context_id = 'context-' ~ category ~ '-' ~ log_index %}
181180

182-
{% if trace %}
183-
<button class="btn-link text-small sf-toggle" data-toggle-selector="#{{ trace_id }}" data-toggle-alt-content="Hide stack trace">Show stack trace</button>
184-
{% endif %}
185-
186-
{% for index, call in trace if index > 1 %}
187-
{% if index == 2 %}
188-
<ul class="sf-call-trace hidden" id="{{ trace_id }}">
189-
{% endif %}
181+
<span class="metadata">
182+
<a class="btn btn-link text-small sf-toggle" data-toggle-selector="#{{ context_id }}" data-toggle-alt-content="Hide trace">Show trace</a>
190183

191-
{% if call.class is defined %}
192-
{% set from = call.class|abbr_class ~ '::' ~ call.function|abbr_method() %}
193-
{% elseif call.function is defined %}
194-
{% set from = call.function|abbr_method %}
195-
{% elseif call.file is defined %}
196-
{% set from = call.file %}
197-
{% else %}
198-
{% set from = '-' %}
199-
{% endif %}
200-
201-
{% set file_name = (call.file is defined and call.line is defined) ? call.file|replace({'\\': '/'})|split('/')|last %}
202-
203-
<li>
204-
{{ from|raw }}
205-
{% if file_name %}
206-
<span class="text-small">(called from {{ call.file|format_file(call.line, file_name)|raw }})</span>
207-
{% endif %}
208-
</li>
209-
210-
{% if index == trace|length - 1 %}
211-
</ul>
212-
{% endif %}
213-
{% endfor %}
214-
{% else %}
215-
{% if log.context is defined and log.context is not empty %}
216-
{% set context_id = 'context-' ~ category ~ '-' ~ log_index %}
217-
{% set context_dump = profiler_dump(log.context) %}
218-
219-
<div class="metadata">
220-
<strong>Context</strong>:
184+
<div id="{{ context_id }}" class="context sf-toggle-content sf-toggle-hidden">
185+
{{ profiler_dump(log.context.seek('exception').seek('\0Exception\0trace'), maxDepth=2) }}
186+
</div>
187+
</span>
188+
{% elseif log.context is defined and log.context is not empty %}
189+
{{ profiler_dump_log(log.message, log.context) }}
221190

222-
{% if context_dump|length > 120 %}
223-
{{ context_dump[:120] }} ...
191+
{% set context_id = 'context-' ~ category ~ '-' ~ log_index %}
224192

225-
<a class="btn-link text-small sf-toggle" data-toggle-selector="#{{ context_id }}" data-toggle-alt-content="Hide full context">Show full context</a>
193+
<span class="metadata">
194+
<a class="btn btn-link text-small sf-toggle" data-toggle-selector="#{{ context_id }}" data-toggle-alt-content="Hide context">Show context</a>
226195

227-
<div id="{{ context_id }}" class="context">
228-
{{ dump(log.context) }}
229-
</div>
230-
{% else %}
231-
{{ context_dump }}
232-
{% endif %}
196+
<div id="{{ context_id }}" class="context sf-toggle-content sf-toggle-hidden">
197+
{{ profiler_dump(log.context, maxDepth=1) }}
233198
</div>
234-
{% endif %}
199+
</span>
200+
{% else %}
201+
{{ log.message }}
235202
{% endif %}
236203
{% endmacro %}

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/profiler.css.twig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ table tbody ul {
184184
.block {
185185
display: block;
186186
}
187+
.full-width {
188+
width: 100%;
189+
}
187190
.hidden {
188191
display: none;
189192
}
@@ -788,6 +791,8 @@ tr.status-warning td {
788791
.tab-content > *:first-child {
789792
margin-top: 0;
790793
}
794+
.tab-navigation li .badge.status-warning { background: {{ colors.warning|raw }}; color: #FFF; }
795+
.tab-navigation li .badge.status-error { background: {{ colors.error|raw }}; color: #FFF; }
791796

792797
{# Toggles
793798
========================================================================= #}
@@ -819,11 +824,17 @@ tr.status-warning td {
819824

820825
{# Logger panel
821826
========================================================================= #}
827+
#collector-content .log-message pre.sf-dump {
828+
display: inline;
829+
padding: 0;
830+
margin: 0;
831+
white-space: normal;
832+
background: none;
833+
}
822834
table.logs .metadata {
823835
color: #777;
824836
display: block;
825837
font-size: 12px;
826-
padding-top: 4px;
827838
}
828839
table.logs .metadata strong {
829840
color: #222;

src/Symfony/Bundle/WebProfilerBundle/Twig/WebProfilerExtension.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public function getFunctions()
7171

7272
return array(
7373
new \Twig_SimpleFunction('profiler_dump', $profilerDump, array('is_safe' => array('html'), 'needs_environment' => true)),
74+
new \Twig_SimpleFunction('profiler_dump_log', array($this, 'dumpLog'), array('is_safe' => array('html'), 'needs_environment' => true)),
7475
);
7576
}
7677

@@ -88,6 +89,23 @@ public function dumpData(\Twig_Environment $env, Data $data, $maxDepth = 0)
8889
return $dump;
8990
}
9091

92+
public function dumpLog(\Twig_Environment $env, $message, Data $context)
93+
{
94+
$message = twig_escape_filter($env, $message);
95+
96+
if (false === strpos($message, '{')) {
97+
return '<span class="log-message">'.$message.'</span>';
98+
}
99+
100+
$replacements = array();
101+
foreach ($context->getRawData()[1] as $k => $v) {
102+
$v = '{'.twig_escape_filter($env, $k).'}';
103+
$replacements['&quot;'.$v.'&quot;'] = $replacements[$v] = $this->dumpData($env, $context->seek($k));
104+
}
105+
106+
return '<span class="log-message">'.strtr($message, $replacements).'</span>';
107+
}
108+
91109
/**
92110
* @deprecated since 3.2, to be removed in 4.0. Use the dumpData() method instead.
93111
*/

src/Symfony/Bundle/WebProfilerBundle/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"symfony/http-kernel": "~3.2",
2121
"symfony/polyfill-php70": "~1.0",
2222
"symfony/routing": "~2.8|~3.0",
23-
"symfony/twig-bridge": "~2.8|~3.0"
23+
"symfony/twig-bridge": "~2.8|~3.0",
24+
"symfony/var-dumper": "~3.2"
2425
},
2526
"require-dev": {
2627
"symfony/config": "~2.8|~3.0",

0 commit comments

Comments
 (0)