Skip to content

Filter logs by level #24263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% set channel_is_defined = (logs|first).channel is defined %}

<table class="logs">
<table class="logs" data-log-levels="Emergency,Alert,Critical,Error,Warning,Notice,Info,Debug" data-default-log-level="Info">
<thead>
<tr>
<th>Level</th>
Expand All @@ -19,7 +18,7 @@
{% set severity = log.context.exception.severity|default(false) %}
{% set status = severity is constant('E_DEPRECATED') or severity is constant('E_USER_DEPRECATED') ? 'warning' : 'normal' %}
{% endif %}
<tr class="status-{{ status }}">
<tr class="status-{{ status }}" data-log-level="{{ log.priorityName|lower }}">
<td class="text-small" nowrap>
<span class="colored text-bold">{{ log.priorityName }}</span>
<span class="text-muted newline">{{ log.timestamp|date('H:i:s') }}</span>
Expand Down
48 changes: 48 additions & 0 deletions src/Symfony/Bundle/TwigBundle/Resources/views/base_js.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,61 @@

toggles[i].setAttribute('data-processed', 'true');
}
},

createLogLevels: function() {
document.querySelectorAll('.logs[data-log-levels]').forEach(function (el) {
var bullets = document.createElement('ul'),
levels = el.getAttribute('data-log-levels').toLowerCase().split(','),
defaultLevel = el.hasAttribute('data-default-log-level') ? levels.indexOf(el.getAttribute('data-default-log-level').toLowerCase()) : levels.length - 1;
addClass(bullets, 'log-levels');
el.getAttribute('data-log-levels').split(',').forEach(function (level, i) {
var bullet = document.createElement('li');
bullet.innerText = level;
bullet.setAttribute('data-log-level', String(i));
bullets.appendChild(bullet);
addEventListener(bullet, 'click', function() {
if (i === this.parentNode.querySelectorAll('.active').length - 1) {
return;
}
this.parentNode.querySelectorAll('li').forEach(function (bullet, j) {
if (parseInt(bullet.getAttribute('data-log-level')) <= levels.indexOf(level.toLowerCase())) {
addClass(bullet, 'active');
if (i === j) {
addClass(bullet, 'last-active');
} else {
removeClass(bullet, 'last-active');
}
} else {
removeClass(bullet, 'active');
removeClass(bullet, 'last-active');
}
});
el.querySelectorAll('tr[data-log-level]').forEach(function (row) {
row.style.display = i < levels.indexOf(row.getAttribute('data-log-level')) ? 'none' : '';
});
});
if (i <= defaultLevel) {
addClass(bullet, 'active');
if (i === defaultLevel) {
addClass(bullet, 'last-active');
}
} else {
el.querySelectorAll('tr[data-log-level="'+level.toLowerCase()+'"]').forEach(function (row) {
row.style.display = 'none';
});
}
});
el.parentNode.insertBefore(bullets, el);
});
}
};
})();

Sfjs.addEventListener(document, 'DOMContentLoaded', function() {
Sfjs.createTabs();
Sfjs.createToggles();
Sfjs.createLogLevels();
});

/*]]>*/</script>
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ header .container { display: flex; justify-content: space-between; }

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

table.logs tr td:last-child { width: 100%; }

.log-levels { width: 100%; margin: 0; padding: 0; display: flex; align-items: center; list-style: none; }
.log-levels li { width: 100%; padding: 3px; margin: 0; cursor: pointer; text-align: center; border: 2px dashed #e0e0e0; border-radius: 5px; color: #888; }
.log-levels li + li { margin-left: 10px; }
.log-levels li.active { background: #eee; color: #666; border-style: solid; border-width: 1px; padding: 4px; border-color: #aaa; }
.log-levels li.last-active { cursor: not-allowed; }

@media (min-width: 575px) {
.hidden-xs-down { display: initial; }
.help-link { margin-left: 30px; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
{% import _self as helper %}
{% set channel_is_defined = (logs|first).channel is defined %}

<table class="logs">
<table class="logs"{% if show_level %} data-log-levels="Emergency,Alert,Critical,Error,Warning,Notice,Info"{% endif %}>
<thead>
<tr>
<th>{{ show_level ? 'Level' : 'Time' }}</th>
Expand All @@ -202,7 +202,7 @@
: log.priorityName in ['CRITICAL', 'ERROR', 'ALERT', 'EMERGENCY'] ? 'status-error'
: log.priorityName == 'WARNING' ? 'status-warning'
%}
<tr class="{{ css_class }}">
<tr class="{{ css_class }}"{% if show_level %} data-log-level="{{ log.priorityName|lower }}"{% endif %}>
<td class="font-normal text-small" nowrap>
{% if show_level %}
<span class="colored text-bold">{{ log.priorityName }}</span>
Expand All @@ -225,6 +225,10 @@
{% endfor %}
</tbody>
</table>

{% if show_level %}
<script>Sfjs.createLogLevels();</script>
{% endif %}
{% endmacro %}

{% macro render_log_message(category, log_index, log) %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,53 @@

toggles[i].setAttribute('data-processed', 'true');
}
},

createLogLevels: function() {
document.querySelectorAll('.logs[data-log-levels]').forEach(function (el) {
var bullets = document.createElement('ul'),
levels = el.getAttribute('data-log-levels').toLowerCase().split(','),
defaultLevel = el.hasAttribute('data-default-log-level') ? levels.indexOf(el.getAttribute('data-default-log-level').toLowerCase()) : levels.length - 1;
addClass(bullets, 'log-levels');
el.getAttribute('data-log-levels').split(',').forEach(function (level, i) {
var bullet = document.createElement('li');
bullet.innerText = level;
bullet.setAttribute('data-log-level', String(i));
bullets.appendChild(bullet);
addEventListener(bullet, 'click', function() {
if (i === this.parentNode.querySelectorAll('.active').length - 1) {
return;
}
this.parentNode.querySelectorAll('li').forEach(function (bullet, j) {
if (parseInt(bullet.getAttribute('data-log-level')) <= levels.indexOf(level.toLowerCase())) {
addClass(bullet, 'active');
if (i === j) {
addClass(bullet, 'last-active');
} else {
removeClass(bullet, 'last-active');
}
} else {
removeClass(bullet, 'active');
removeClass(bullet, 'last-active');
}
});
el.querySelectorAll('tr[data-log-level]').forEach(function (row) {
row.style.display = i < levels.indexOf(row.getAttribute('data-log-level')) ? 'none' : '';
});
});
if (i <= defaultLevel) {
addClass(bullet, 'active');
if (i === defaultLevel) {
addClass(bullet, 'last-active');
}
} else {
el.querySelectorAll('tr[data-log-level="'+level.toLowerCase()+'"]').forEach(function (row) {
row.style.display = 'none';
});
}
});
el.parentNode.insertBefore(bullets, el);
});
}
};
})();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,13 @@ table.logs .metadata {
display: block;
font-size: 12px;
}
table.logs tr td:last-child { width: 100%; }

.log-levels { width: 100%; margin: 0; padding: 0; display: flex; align-items: center; list-style: none; }
.log-levels li { width: 100%; padding: 3px; margin: 0; cursor: pointer; text-align: center; border: 2px dashed #e0e0e0; border-radius: 5px; color: #888; }
.log-levels li + li { margin-left: 10px; }
.log-levels li.active { background: #eee; color: #666; border-style: solid; border-width: 1px; padding: 4px; border-color: #aaa; }
.log-levels li.last-active { cursor: not-allowed; }

{# Doctrine panel
========================================================================= #}
Expand Down