8000 feature #24263 Filter logs by level (ro0NL) · symfony/symfony@6de1577 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6de1577

Browse files
committed
feature #24263 Filter logs by level (ro0NL)
This PR was submitted for the 3.4 branch but it was merged into the 4.2-dev branch instead (closes #24263). Discussion ---------- Filter logs by level | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!--highly recommended for new features--> Proposal to filter logs by level. This PR competes with #23247 (but also see #23038) which propose to filter by channel. <details> <summary>Before</summary> ![image](https://user-images.githubusercontent.com/1047696/30607022-00536bbe-9d74-11e7-84dd-6427d328f50b.png) </details> <details> <summary>After</summary> ![image](https://user-images.githubusercontent.com/1047696/31036405-6346da12-a56c-11e7-8747-b1ae89c549f2.png) </details> From #23247 (comment) > Adding configuration is always adding complexity for the end user. If we can do otherwise (including doing nothing), i think that might be better. I all depends on the current "brokenness" status. This avoids that. Also single click; noise gone. Commits ------- 8f88753 Filter logs by level
2 parents 61d336b + 8f88753 commit 6de1577

File tree

6 files changed

+118
-5
lines changed

6 files changed

+118
-5
lines changed

src/Symfony/Bundle/TwigBundle/Resources/views/Exception/logs.html.twig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{% set channel_is_defined = (logs|first).channel is defined %}
2-
3-
<table class="logs">
2+
<table class="logs" data-log-levels="Emergency,Alert,Critical,Error,Warning,Notice,Info,Debug" data-default-log-level="Info">
43
<thead>
54
<tr>
65
<th>Level</th>
@@ -19,7 +18,7 @@
1918
{% set severity = log.context.exception.severity|default(false) %}
2019
{% set status = severity is constant('E_DEPRECATED') or severity is constant('E_USER_DEPRECATED') ? 'warning' : 'normal' %}
2120
{% endif %}
22-
<tr class="status-{{ status }}">
21+
<tr class="status-{{ status }}" data-log-level="{{ log.priorityName|lower }}">
2322
<td class="text-small" nowrap>
2423
<span class="colored text-bold">{{ log.priorityName }}</span>
2524
<span class="text-muted newline">{{ log.timestamp|date('H:i:s') }}</span>

src/Symfony/Bundle/TwigBundle/Resources/views/base_js.html.twig

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,61 @@
171171
172172
toggles[i].setAttribute('data-processed', 'true');
173173
}
174+
},
175+
176+
createLogLevels: function() {
177+
document.querySelectorAll('.logs[data-log-levels]').forEach(function (el) {
178+
var bullets = document.createElement('ul'),
179+
levels = el.getAttribute('data-log-levels').toLowerCase().split(','),
180+
defaultLevel = el.hasAttribute('data-default-log-level') ? levels.indexOf(el.getAttribute('data-default-log-level').toLowerCase()) : levels.length - 1;
181+
addClass(bullets, 'log-levels');
182+
el.getAttribute('data-log-levels').split(',').forEach(function (level, i) {
183+
var bullet = document.createElement('li');
184+
bullet.innerText = level;
185+
bullet.setAttribute('data-log-level', String(i));
186+
bullets.appendChild(bullet);
187+
addEventListener(bullet, 'click', function() {
188+
if (i === this.parentNode.querySelectorAll('.active').length - 1) {
189+
return;
190+
}
191+
this.parentNode.querySelectorAll('li').forEach(function (bullet, j) {
192+
if (parseInt(bullet.getAttribute('data-log-level')) <= levels.indexOf(level.toLowerCase())) {
193+
addClass(bullet, 'active');
194+
if (i === j) {
195+
addClass(bullet, 'last-active');
196+
} else {
197+
removeClass(bullet, 'last-active');
198+
}
199+
} else {
200+
removeClass(bullet, 'active');
201+
removeClass(bullet, 'last-active');
202+
}
203+
});
204+
el.querySelectorAll('tr[data-log-level]').forEach(function (row) {
205+
row.style.display = i < levels.indexOf(row.getAttribute('data-log-level')) ? 'none' : '';
206+
});
207+
});
208+
if (i <= defaultLevel) {
209+
addClass(bullet, 'active');
210+
if (i === defaultLevel) {
211+
addClass(bullet, 'last-active');
212+
}
213+
} else {
214+
el.querySelectorAll('tr[data-log-level="'+level.toLowerCase()+'"]').forEach(function (row) {
215+
row.style.display = 'none';
216+
});
217+
}
218+
});
219+
el.parentNode.insertBefore(bullets, el);
220+
});
174221
}
175222
};
176223
})();
177224
178225
Sfjs.addEventListener(document, 'DOMContentLoaded', function() {
179226
Sfjs.createTabs();
180227
Sfjs.createToggles();
228+
Sfjs.createLogLevels();
181229
});
182230
183231
/*]]>*/</script>

src/Symfony/Bundle/TwigBundle/Resources/views/exception.css.twig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ header .container { display: flex; justify-content: space-between; }
125125

126126
.trace-as-text .stacktrace { line-height: 1.8; margin: 0 0 15px; white-space: pre-wrap; }
127127

128+
table.logs tr td:last-child { width: 100%; }
129+
130+
.log-levels { width: 100%; margin: 0; padding: 0; display: flex; align-items: center; list-style: none; }
131+
.log-levels li { width: 100%; padding: 3px; margin: 0; cursor: pointer; text-align: center; border: 2px dashed #e0e0e0; border-radius: 5px; color: #888; }
132+
.log-levels li + li { margin-left: 10px; }
133+
.log-levels li.active { background: #eee; color: #666; border-style: solid; border-width: 1px; padding: 4px; border-color: #aaa; }
134+
.log-levels li.last-active { cursor: not-allowed; }
135+
128136
@media (min-width: 575px) {
129137
.hidden-xs-down { display: initial; }
130138
.help-link { margin-left: 30px; }

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
{% import _self as helper %}
188188
{% set channel_is_defined = (logs|first).channel is defined %}
189189

190-
<table class="logs">
190+
<table class="logs"{% if show_level %} data-log-levels="Emergency,Alert,Critical,Error,Warning,Notice,Info"{% endif %}>
191191
<thead>
192192
<tr>
193193
<th>{{ show_level ? 'Level' : 'Time' }}</th>
@@ -202,7 +202,7 @@
202202
: log.priorityName in ['CRITICAL', 'ERROR', 'ALERT', 'EMERGENCY'] ? 'status-error'
203203
: log.priorityName == 'WARNING' ? 'status-warning'
204204
%}
205-
<tr class="{{ css_class }}">
205+
<tr class="{{ css_class }}"{% if show_level %} data-log-level="{{ log.priorityName|lower }}"{% endif %}>
206206
<td class="font-normal text-small" nowrap>
207207
{% if show_level %}
208208
<span class="colored text-bold">{{ log.priorityName }}</span>
@@ -225,6 +225,10 @@
225225
{% endfor %}
226226
</tbody>
227227
</table>
228+
229+
{% if show_level %}
230+
<script>Sfjs.createLogLevels();</script>
231+
{% endif %}
228232
{% endmacro %}
229233

230234
{% macro render_log_message(category, log_index, log) %}

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,53 @@
682682
683683
toggles[i].setAttribute('data-processed', 'true');
684684
}
685+
},
686+
687+
createLogLevels: function() {
688+
document.querySelectorAll('.logs[data-log-levels]').forEach(function (el) {
689+
var bullets = document.createElement('ul'),
690+
levels = el.getAttribute('data-log-levels').toLowerCase().split(','),
691+
defaultLevel = el.hasAttribute('data-default-log-level') ? levels.indexOf(el.getAttribute('data-default-log-level').toLowerCase()) : levels.length - 1;
692+
addClass(bullets, 'log-levels');
693+
el.getAttribute('data-log-levels').split(',').forEach(function (level, i) {
694+
var bullet = document.createElement('li');
695+
bullet.innerText = level;
696+
bullet.setAttribute('data-log-level', String(i));
697+
bullets.appendChild(bullet);
698+
addEventListener(bullet, 'click', function() {
699+
if (i === this.parentNode.querySelectorAll('.active').length - 1) {
700+
return;
701+
}
702+
this.parentNode.querySelectorAll('li').forEach(function (bullet, j) {
703+
if (parseInt(bullet.getAttribute('data-log-level')) <= levels.indexOf(level.toLowerCase())) {
704+
addClass(bullet, 'active');
705+
if (i === j) {
706+
addClass(bullet, 'last-active');
707+
} else {
708+
removeClass(bullet, 'last-active');
709+
}
710+
} else {
711+
removeClass(bullet, 'active');
712+
removeClass(bullet, 'last-active');
713+
}
714+
});
715+
el.querySelectorAll('tr[data-log-level]').forEach(function (row) {
716+
row.style.display = i < levels.indexOf(row.getAttribute('data-log-level')) ? 'none' : '';
717+
});
718+
});
719+
if (i <= defaultLevel) {
720+
addClass(bullet, 'active');
721+
if (i === defaultLevel) {
722+
addClass(bullet, 'last-active');
723+
}
724+
} else {
725+
el.querySelectorAll('tr[data-log-level="'+level.toLowerCase()+'"]').forEach(function (row) {
726+
row.style.display = 'none';
727+
});
728+
}
729+
});
730+
el.parentNode.insertBefore(bullets, el);
731+
});
685732
}
686733
};
687734
})();

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,13 @@ table.logs .metadata {
955955
display: block;
956956
font-size: 12px;
957957
}
958+
table.logs tr td:last-child { width: 100%; }
959+
960+
.log-levels { width: 100%; margin: 0; padding: 0; display: flex; align-items: center; list-style: none; }
961+
.log-levels li { width: 100%; padding: 3px; margin: 0; cursor: pointer; text-align: center; border: 2px dashed #e0e0e0; border-radius: 5px; color: #888; }
962+
.log-levels li + li { margin-left: 10px; }
963+
.log-levels li.active { background: #eee; color: #666; border-style: solid; border-width: 1px; padding: 4px; border-color: #aaa; }
964+
.log-levels li.last-active { cursor: not-allowed; }
958965

959966
{# Doctrine panel
960967
========================================================================= #}

0 commit comments

Comments
 (0)
0