8000 [HttpKernel] Use VarDumper in the Logs&Events panels of the profiler · symfony/symfony@eddecbd · GitHub
[go: up one dir, main page]

Skip to content

Commit eddecbd

Browse files
nicolas-grekaswouterj
authored andcommitted
[HttpKernel] Use VarDumper in the Logs&Events panels of the profiler
1 parent 41a7649 commit eddecbd

File tree

9 files changed

+140
-230
lines changed

9 files changed

+140
-230
lines changed

src/Symfony/Bundle/DebugBundle/Resources/views/Profiler/dump.html.twig

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
{% for dump in collector.getDumps('html') %}
4747
<div class="sf-dump sf-reset">
48-
<h3>In
48+
<span class="metadata">In
4949
{% if dump.line %}
5050
{% set link = dump.file|file_link(dump.line) %}
5151
{% if link %}
@@ -56,10 +56,8 @@
5656
{% else %}
5757
{{ dump.name }}
5858
{% endif %}
59-
<small>line {{ dump.line }}</small>
60-
61-
<a class="text-small sf-toggle" data-toggle-selector="#sf-trace-{{ loop.index0 }}" data-toggle-alt-content="Hide code">Show code</a>
62-
</h3>
59+
line <a class="text-small sf-toggle" data-toggle-selector="#sf-trace-{{ loop.index0 }}">{{ dump.line }}</a>:
60+
</span>
6361

6462
<div class="sf-dump-compact hidden" id="sf-trace-{{ loop.index0 }}">
6563
<div class="trace">

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: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ table tbody ul {
190190
.block {
191191
display: block;
192192
}
193+
.full-width {
194+
width: 100%;
195+
}
193196
.hidden {
194197
display: none;
195198
}
@@ -806,6 +809,8 @@ tr.status-warning td {
806809
.tab-content > *:first-child {
807810
margin-top: 0;
808811
}
812+
.tab-navigation li .badge.status-warning { background: {{ colors.warning|raw }}; color: #FFF; }
813+
.tab-navigation li .badge.status-error { background: {{ colors.error|raw }}; color: #FFF; }
809814

810815
{# Toggles
811816
========================================================================= #}
@@ -838,32 +843,8 @@ tr.status-warning td {
838843
{# Logger panel
839844
========================================================================= #}
840845
table.logs .metadata {
841-
color: #777;
842846
display: block;
843847
font-size: 12px;
844-
padding-top: 4px;
845-
}
846-
table.logs .metadata strong {
847-
color: #222;
848-
}
849-
table.logs .metadata .context {
850-
background: #F5F5F5;
851-
color: #222;
852-
}
853-
table.logs .metadata .context pre {
854-
margin: 5px 0;
855-
padding: 5px 10px;
856-
white-space: pre-wrap;
857-
}
858-
859-
table.logs .sf-call-stack {
860-
margin: 1em 0 1em 1.5em;
861-
}
862-
table.logs .sf-call-stack li {
863-
margin-bottom: 5px;
864-
}
865-
table.logs .sf-call-stack abbr {
866-
border: none;
867848
}
868849

869850
{# Doctrine panel
@@ -889,13 +870,16 @@ table.logs .sf-call-stack abbr {
889870
#collector-content .sf-dump samp {
890871
{{ mixins.monospace_font|raw }}
891872
}
892-
#collector-content .sf-dump h3 {
893-
font-size: 18px;
894-
margin: .5em 0 0;
895-
}
896-
#collector-content .sf-dump h3 a {
873+
#collector-content .sf-dump a {
897874
cursor: pointer;
898875
}
876+
#collector-content .sf-dump pre.sf-dump,
877+
#collector-content .sf-dump .trace {
878+
border: 1px solid #DDD;
879+
background: #FFF;
880+
padding: 10px;
881+
margin: 0.5em 0;
882+
}
899883

900884
#collector-content pre.sf-dump { color: #CC7832; }
901885
#collector-content .sf-dump-str { color: #629755; }
@@ -924,21 +908,12 @@ table.logs .sf-call-stack abbr {
924908
width: 4em;
925909
}
926910

927-
#collector-content .sf-dump .trace {
928-
border: 1px solid #DDD;
929-
background: #FFF;
930-
padding: 10px;
931-
margin: 1em 0;
932-
}
933911
#collector-con C2EE tent .sf-dump .trace {
934912
font-size: 12px;
935913
}
936-
#collector-content .sf-dump .trace code {
937-
font-size: 14px;
938-
}
939914
#collector-content .sf-dump .trace li {
940915
margin-bottom: 0;
941-
padding: 5px 0;
916+
padding: 0;
942917
}
943918
#collector-content .sf-dump .trace li.selected {
944919
background: rgba(255, 255, 153, 0.5);

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 str_replace("\n</pre", '</pre', rtrim($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="dump-inline">'.$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="dump-inline">'.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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
"symfony/dependency-injection": "~2.8|~3.0",
3030
"symfony/stopwatch": "~2.8|~3.0"
3131
},
32+
"conflict": {
33+
"symfony/event-dispatcher": "<3.2"
34+
},
3235
"autoload": {
3336
"psr-4": { "Symfony\\Bundle\\WebProfilerBundle\\": "" },
3437
"exclude-from-classmap": [

0 commit comments

Comments
 (0)
0