10000 [WebProfilerBundle] Redesigned the log section by javiereguiluz · Pull Request #42195 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[WebProfilerBundle] Redesigned the log section #42195

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
Jul 23, 2021
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
11 changes: 10 additions & 1 deletion src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,17 @@ public function __invoke(array $record)
{
$hash = $this->requestStack && ($request = $this->requestStack->getCurrentRequest()) ? spl_object_hash($request) : '';

$timestamp = $timestampRfc3339 = false;
if ($record['datetime'] instanceof \DateTimeInterface) {
$timestamp = $record['datetime']->getTimestamp();
$timestampRfc3339 = $record['datetime']->format(\DateTimeInterface::RFC3339_EXTENDED);
} elseif (false !== $timestamp = strtotime($record['datetime'])) {
$timestampRfc3339 = (new \DateTimeImmutable($record['datetime']))->format(\DateTimeInterface::RFC3339_EXTENDED);
}

$this->records[$hash][] = [
'timestamp' => $record['datetime'] instanceof \DateTimeInterface ? $record['datetime']->getTimestamp() : strtotime($record['datetime']),
'timestamp' => $timestamp,
'timestamp_rfc3339' => $timestampRfc3339,
'message' => $record['message'],
'priority' => $record['level'],
'priorityName' => $record['level_name'],
Expand Down
24 changes: 24 additions & 0 deletions src/Symfony/Bridge/Monolog/Tests/Processor/DebugProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,30 @@ public function providerDatetimeFormatTests(): array
];
}

/**
* @dataProvider providerDatetimeRfc3339FormatTests
*/
public function testDatetimeRfc3339Format(array $record, $expectedTimestamp)
{
$processor = new DebugProcessor();
$processor($record);

$records = $processor->getLogs();
self::assertCount(1, $records);
self::assertSame($expectedTimestamp, $records[0]['timestamp_rfc3339']);
}

public function providerDatetimeRfc3339FormatTests(): array
{
$record = $this->getRecord();

return [
[array_merge($record, ['datetime' => new \DateTime('2019-01-01T00:01:00+00:00')]), '2019-01-01T00:01:00.000+00:00'],
[array_merge($record, ['datetime' => '2019-01-01T00:01:00+00:00']), '2019-01-01T00:01:00.000+00:00'],
[array_merge($record, ['datetime' => 'foo']), false],
];
}

public function testDebugProcessor()
{
$processor = new DebugProcessor();
Expand Down

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -709,104 +709,78 @@ if (typeof Sfjs === 'undefined' || typeof Sfjs.loadToolbar === 'undefined') {
}
},

createFilters: function() {
document.querySelectorAll('[data-filters] [data-filter]').forEach(function (filter) {
var filters = filter.closest('[data-filters]'),
type = 'choice',
name = filter.dataset.filter,
ucName = name.charAt(0).toUpperCase()+name.slice(1),
list = document.createElement('ul'),
values = filters.dataset['filter'+ucName] || filters.querySelectorAll('[data-filter-'+name+']'),
labels = {},
defaults = null,
indexed = {},
processed = {};
if (typeof values === 'string') {
type = 'level';
labels = values.split(',');
values = values.toLowerCase().split(',');
defaults = values.length - 1;
}
addClass(list, 'filter-list');
addClass(list, 'filter-list-'+type);
values.forEach(function (value, i) {
if (value instanceof HTMLElement) {
value = value.dataset['filter'+ucName];
}
if (value in processed) {
return;
}
var option = document.createElement('li'),
label = i in labels ? labels[i] : value,
active = false,
matches;
if ('' === label) {
option.innerHTML = '<em>(none)</em>';
} else {
option.innerText = label;
}
option.dataset.filter = value;
option.setAttribute('title', 1 === (matches = filters.querySelectorAll('[data-filter-'+name+'="'+value+'"]').length) ? 'Matches 1 row' : 'Matches '+matches+' rows');
indexed[value] = i;
list.appendChild(option);
addEventListener(option, 'click', function () {
if ('choice' === type) {
filters.querySelectorAll('[data-filter-'+name+']').forEach(function (row) {
if (option.dataset.filter === row.dataset['filter'+ucName]) {
toggleClass(row, 'filter-hidden-'+name);
}
});
toggleClass(option, 'active');
} else if ('level' === type) {
if (i === this.parentNode.querySelectorAll('.active').length - 1) {
return;
}
this.parentNode.querySelectorAll('li').forEach(function (currentOption, j) {
if (j <= i) {
addClass(currentOption, 'active');
if (i === j) {
addClass(currentOption, 'last-active');
} else {
removeClass(currentOption, 'last-active');
}
} else {
removeClass(currentOption, 'active');
removeClass(currentOption, 'last-active');
}
});
filters.querySelectorAll('[data-filter-'+name+']').forEach(function (row) {
if (i < indexed[row.dataset['filter'+ucName]]) {
addClass(row, 'filter-hidden-'+name);
} else {
removeClass(row, 'filter-hidden-'+name);
}
});
}
initializeLogsTable: function() {
Sfjs.updateLogsTable();

document.querySelectorAll('.log-filter input').forEach((input) => {
input.addEventListener('change', () => { Sfjs.updateLogsTable(); });
});

document.querySelectorAll('.filter-select-all-or-none a').forEach((link) => {
link.addEventListener('click', () => {
const selectAll = link.classList.contains('select-all');
link.closest('.log-filter-content').querySelectorAll('input').forEach((input) => {
input.checked = selectAll;
});
if ('choice' === type) {
active = null === defaults || 0 <= defaults.indexOf(value);
} else if ('level' === type) {
active = i <= defaults;
if (active && i === defaults) {
addClass(option, 'last-active');
}
}
if (active) {
addClass(option, 'active');
} else {
filters.querySelectorAll('[data-filter-'+name+'="'+value+'"]').forEach(function (row) {
toggleClass(row, 'filter-hidden-'+name);
});

Sfjs.updateLogsTable();
});
});

document.body.addEventListener('click', (event) => {
document.querySelectorAll('details.log-filter').forEach((filterElement) => {
if (!filterElement.contains(event.target) && filterElement.open) {
filterElement.open = false;
}
processed[value] = true;
});
});
},

updateLogsTable: function() {
const selectedType = document.querySelector('#log-filter-type input:checked').value;
const priorities = document.querySelectorAll('#log-filter-priority input');
const selectedPriorities = Array.from(priorities).filter((input) => input.checked).map((input) => input.value);
const channels = document.querySelectorAll('#log-filter-channel input');
const selectedChannels = Array.from(channels).filter((input) => input.checked).map((input) => input.value);

const logs = document.querySelector('table.logs');
if (null === logs) {
return;
}

// hide rows that don't match the current filters
let numVisibleRows = 0;
logs.querySelectorAll('tbody tr').forEach((row) => {
if ('all' !== selectedType && selectedType !== row.getAttribute('data-type')) {
row.style.display = 'none';
return;
}

if (1 < list.childNodes.length) {
filter.appendChild(list);
filter.dataset.filtered = '';
if (false === selectedPriorities.includes(row.getAttribute('data-priority'))) {
row.style.display = 'none';
return;
}

if ('' !== row.getAttribute('data-channel') && false === selectedChannels.includes(row.getAttribute('data-channel'))) {
row.style.display = 'none';
return;
}

row.style.display = 'table-row';
numVisibleRows++;
});
}

document.querySelector('table.logs').style.display = 0 === numVisibleRows ? 'none' : 'table';
document.querySelector('.no-logs-message').style.display = 0 === numVisibleRows ? 'block' : 'none';

// update the selected totals of all filters
document.querySelector('#log-filter-priority .filter-active-num').innerText = (priorities.length === selectedPriorities.length) ? 'All' : selectedPriorities.length;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be .textContent rather than .innerText to use the standard method

document.querySelector('#log-filter-channel .filter-active-num').innerText = (channels.length === selectedChannels.length) ? 'All' : selectedChannels.length;

// update the currently selected "log type" tab
document.querySelectorAll('#log-filter-type li').forEach((tab) => tab.classList.remove('active'));
document.querySelector(`#log-filter-type input[value="${selectedType}"]`).parentElement.classList.add('active');
},
};
})();

Expand Down
Loading
0