Skip to content

Commit 33f0e5e

Browse files
javiereguiluzfabpot
authored andcommitted
Improved the logger panel when the log context is very long
1 parent ff87f30 commit 33f0e5e

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

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

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<p>There are no log messages of this level.</p>
7777
</div>
7878
{% else %}
79-
{{ helper.render_table(info_and_error_logs, true) }}
79+
{{ helper.render_table(info_and_error_logs, 'info', true) }}
8080
{% endif %}
8181
</div>
8282
</div>
@@ -92,7 +92,7 @@
9292
<p>There are no log messages about deprecated features.</p>
9393
</div>
9494
{% else %}
95-
{{ helper.render_table(deprecation_logs, false, true) }}
95+
{{ helper.render_table(deprecation_logs, 'deprecation', false, true) }}
9696
{% endif %}
9797
</div>
9898
</div>
@@ -106,7 +106,7 @@
106106
<p>There are no log messages of this level.</p>
107107
</div>
108108
{% else %}
109-
{{ helper.render_table(debug_logs) }}
109+
{{ helper.render_table(debug_logs, 'debug') }}
110110
{% endif %}
111111
</div>
112112
</div>
@@ -120,7 +120,7 @@
120120
<p>There are no log messages of this level.</p>
121121
</div>
122122
{% else %}
123-
{{ helper.render_table(silenced_logs) }}
123+
{{ helper.render_table(silenced_logs, 'silenced') }}
124124
{% endif %}
125125
</div>
126126
</div>
@@ -129,7 +129,7 @@
129129
{% endif %}
130130
{% endblock %}
131131

132-
{% macro render_table(logs, show_level = false, is_deprecation = false) %}
132+
{% macro render_table(logs, category = '', show_level = false, is_deprecation = false) %}
133133
{% import _self as helper %}
134134
{% set channel_is_defined = (logs|first).channel is defined %}
135135

@@ -160,31 +160,31 @@
160160
<td class="font-normal text-small text-bold nowrap">{{ log.channel }}</td>
161161
{% endif %}
162162

163-
<td class="font-normal">{{ helper.render_log_message(loop.index, log, is_deprecation) }}</td>
163+
<td class="font-normal">{{ helper.render_log_message(category, loop.index, log, is_deprecation) }}</td>
164164
</tr>
165165
{% endfor %}
166166
</tbody>
167167
</table>
168168
{% endmacro %}
169169

170-
{% macro render_log_message(log_index, log, is_deprecation = false) %}
170+
{% macro render_log_message(category, log_index, log, is_deprecation = false) %}
171171
{{ log.message }}
172172

173173
{% if is_deprecation %}
174174
{% set stack = log.context.stack|default([]) %}
175-
{% set id = 'sf-call-stack-' ~ log_index %}
175+
{% set stack_id = 'sf-call-stack-' ~ category ~ '-' ~ log_index %}
176176

177177
{% if log.context.errorCount is defined %}
178178
<span class="text-small text-bold">({{ log.context.errorCount }} times)</span>
179179
{% endif %}
180180

181181
{% if stack %}
182-
<button class="btn-link text-small sf-toggle" data-toggle-selector="#{{ id }}" data-toggle-alt-content="Hide stack trace">Show stack trace</button>
182+
<button class="btn-link text-small sf-toggle" data-toggle-selector="#{{ stack_id }}" data-toggle-alt-content="Hide stack trace">Show stack trace</button>
183183
{% endif %}
184184

185185
{% for index, call in stack if index > 1 %}
186186
{% if index == 2 %}
187-
<ul class="sf-call-stack hidden" id="{{ id }}">
187+
<ul class="sf-call-stack hidden" id="{{ stack_id }}">
188188
{% endif %}
189189

190190
{% if call.class is defined %}
@@ -212,11 +212,24 @@
212212
{% endfor %}
213213
{% else %}
214214
{% if log.context is defined and log.context is not empty %}
215-
<span class="metadata">
216-
<strong>Context</strong>: {{ log.context|json_encode(64 b-or 256)|replace({
217-
'{"' : '{ "', '"}' : '" }', '":{' : '": {', '":"' : '": "', '","' : '", "'
218-
}) }}
219-
</span>
215+
{% set context_id = 'context-' ~ category ~ '-' ~ log_index %}
216+
{% set context_dump = profiler_dump(log.context) %}
217+
218+
<div class="metadata">
219+
<strong>Context</strong>:
220+
221+
{% if context_dump|length > 120 %}
222+
{{ context_dump[:120] }} ...
223+
224+
<a class="btn-link text-small sf-toggle" data-toggle-selector="#{{ context_id }}" data-toggle-alt-content="Hide full context">Show full context</a>
225+
226+
<div id="{{ context_id }}" class="context">
227+
<pre>{{ context_dump }}</pre>
228+
</div>
229+
{% else %}
230+
{{ context_dump }}
231+
{% endif %}
232+
</div>
220233
{% endif %}
221234
{% endif %}
222235
{% endmacro %}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,14 @@ table.logs .metadata {
816816
table.logs .metadata strong {
817817
color: #222;
818818
}
819+
table.logs .metadata .context {
820+
background: #F5F5F5;
821+
color: #222;
822+
}
823+
table.logs .metadata .context pre {
824+
margin: 5px 0;
825+
padding: 5px 10px;
826+
}
819827

820828
table.logs .sf-call-stack {
821829
margin: 1em 0 1em 1.5em;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy