82 lines
3.2 KiB
HTML
82 lines
3.2 KiB
HTML
<?php
|
||
/**
|
||
* @package Bicycle
|
||
* @description logs.html — просмотр и поиск логов
|
||
*
|
||
* @var array $entries Записи лога [['datetime','level','message','channel'], ...]
|
||
* @var array $filters Текущие фильтры [date, channel, level, q]
|
||
* @var array $dates Доступные даты (Y-m-d)
|
||
*/
|
||
|
||
// Цвет badge по уровню.
|
||
$level_class = static fn(string $l): string => [
|
||
'error' => 'danger',
|
||
'warning' => 'warning',
|
||
'info' => 'primary',
|
||
'debug' => 'secondary',
|
||
][$l] ?? 'secondary';
|
||
|
||
$this->setScript('logs.js');
|
||
?>
|
||
<h1 class="h3 mb-3">Логи</h1>
|
||
|
||
<form method="get" class="row g-2 mb-3" id="logs-filters">
|
||
<div class="col-auto">
|
||
<select name="date" class="form-select">
|
||
<?php if (!in_array($filters['date'], $dates, true)): ?>
|
||
<option value="<?= htmlspecialchars($filters['date'], ENT_QUOTES) ?>" selected>
|
||
<?= htmlspecialchars($filters['date'], ENT_QUOTES) ?>
|
||
</option>
|
||
<?php endif; ?>
|
||
<?php foreach ($dates as $d): ?>
|
||
<option value="<?= $d ?>"<?= $d === $filters['date'] ? ' selected' : '' ?>><?= $d ?></option>
|
||
<?php endforeach; ?>
|
||
</select>
|
||
</div>
|
||
<div class="col-auto">
|
||
<select name="channel" class="form-select">
|
||
<option value="action"<?= $filters['channel'] === 'action' ? ' selected' : '' ?>>Действия</option>
|
||
<option value="error"<?= $filters['channel'] === 'error' ? ' selected' : '' ?>>Ошибки</option>
|
||
<option value="all"<?= $filters['channel'] === 'all' ? ' selected' : '' ?>>Все</option>
|
||
</select>
|
||
</div>
|
||
<div class="col-auto">
|
||
<select name="level" class="form-select">
|
||
<option value="">Все уровни</option>
|
||
<?php foreach (['debug', 'info', 'warning', 'error'] as $lvl): ?>
|
||
<option value="<?= $lvl ?>"<?= $filters['level'] === $lvl ? ' selected' : '' ?>><?= $lvl ?></option>
|
||
<?php endforeach; ?>
|
||
</select>
|
||
</div>
|
||
<div class="col-auto">
|
||
<input type="text" name="q" class="form-control" placeholder="Поиск по тексту"
|
||
value="<?= htmlspecialchars($filters['q'], ENT_QUOTES) ?>">
|
||
</div>
|
||
<div class="col-auto">
|
||
<button type="submit" class="btn btn-primary">Найти</button>
|
||
</div>
|
||
</form>
|
||
|
||
<?php if (empty($entries)): ?>
|
||
<div class="alert alert-secondary">Записей нет.</div>
|
||
<?php else: ?>
|
||
<table class="table table-sm table-striped align-middle">
|
||
<thead>
|
||
<tr>
|
||
<th class="text-nowrap">Время</th>
|
||
<th>Уровень</th>
|
||
<th>Сообщение</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php foreach ($entries as $e): ?>
|
||
<tr>
|
||
<td class="text-nowrap"><?= htmlspecialchars($e['datetime'], ENT_QUOTES) ?></td>
|
||
<td><span class="badge bg-<?= $level_class($e['level']) ?>"><?= htmlspecialchars($e['level'], ENT_QUOTES) ?></span></td>
|
||
<td><?= htmlspecialchars($e['message'], ENT_QUOTES, 'UTF-8') ?></td>
|
||
</tr>
|
||
<?php endforeach; ?>
|
||
</tbody>
|
||
</table>
|
||
<?php endif; ?>
|