Files
ewoooc/logs.html
ogt 1b4f3a7bbe
Some checks failed
CD Pipeline / deploy (push) Failing after 59s
feat: EwoooC 初始化 — 完整專案推版至 Gitea
- 建立 Gitea Actions CD pipeline (.gitea/workflows/cd.yaml)
- 部署模式: rsync Python 檔案至 188 → docker restart (volume mount)
- Dockerfile/requirements 變動時自動重建 Docker image
- 部署通知: Telegram (開始/成功/失敗)
- 健康檢查: https://mo.wooo.work/health (最多 5 次重試)
- 同步最新 CLAUDE.md / ADR-008 / memory (2026-04-19)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-19 01:21:13 +08:00

1184 lines
36 KiB
HTML

<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>系統日誌 - MOMO 監控</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
background: linear-gradient(135deg, #f5f7fa 0%, #e8ecf1 100%);
min-height: 100vh;
padding-top: 70px;
}
.navbar-dark.bg-primary {
background: linear-gradient(135deg, #4F46E5 0%, #6366F1 100%) !important;
box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}
.navbar-dark .navbar-brand {
color: #ffffff !important;
font-weight: 600;
}
.navbar-dark .navbar-nav .nav-link {
color: rgba(255, 255, 255, 0.9) !important;
font-weight: 500;
transition: all 0.3s;
}
.navbar-dark .navbar-nav .nav-link:hover {
color: #ffffff !important;
background: rgba(255, 255, 255, 0.1);
border-radius: 6px;
}
.navbar-dark .navbar-nav .nav-link.active {
color: #ffffff !important;
background: rgba(255, 255, 255, 0.15);
border-radius: 6px;
font-weight: 600;
}
.navbar-dark .navbar-text {
color: rgba(255, 255, 255, 0.8) !important;
}
/* Custom Dark Gray Navbar */
.navbar.bg-custom-dark {
background: linear-gradient(135deg, #1f2937 0%, #374151 100%);
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
border-bottom: 1px solid rgba(255,255,255,0.1);
}
.navbar.bg-custom-dark .navbar-brand {
color: #ffffff;
font-weight: 600;
}
.navbar.bg-custom-dark .navbar-nav .nav-link {
color: rgba(255, 255, 255, 0.85);
font-weight: 500;
}
.navbar.bg-custom-dark .navbar-nav .nav-link:hover {
color: #ffffff;
}
.navbar.bg-custom-dark .navbar-nav .nav-link.active {
color: #ffffff;
font-weight: 600;
}
.navbar.bg-custom-dark .navbar-text {
color: rgba(255, 255, 255, 0.75);
}
/* Page Header */
.page-header {
background: white;
padding: 25px 30px;
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0,0,0,0.06);
margin-bottom: 30px;
display: flex;
justify-content: space-between;
align-items: center;
}
.page-header h4 {
margin: 0;
color: #1f2937;
font-weight: 600;
}
.status-indicators {
display: flex;
gap: 20px;
align-items: center;
}
.status-item {
display: flex;
align-items: center;
gap: 8px;
font-size: 13px;
color: #6b7280;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #10b981;
animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
/* Control Panel */
.control-panel {
background: white;
padding: 25px;
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0,0,0,0.06);
margin-bottom: 25px;
}
.control-section {
margin-bottom: 20px;
}
.control-section:last-child {
margin-bottom: 0;
}
.control-section-title {
font-size: 13px;
font-weight: 600;
color: #6b7280;
text-transform: uppercase;
letter-spacing: 0.5px;
margin-bottom: 12px;
}
.control-buttons {
display: flex;
gap: 10px;
flex-wrap: wrap;
}
.btn-control {
padding: 10px 18px;
border: none;
border-radius: 8px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: all 0.3s;
display: inline-flex;
align-items: center;
gap: 8px;
}
.btn-refresh {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
box-shadow: 0 2px 6px rgba(102, 126, 234, 0.3);
}
.btn-refresh:hover {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}
.btn-refresh.spinning i {
animation: spin 1s linear infinite;
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.btn-pause {
background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
color: white;
box-shadow: 0 2px 6px rgba(245, 158, 11, 0.3);
}
.btn-pause:hover {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4);
}
.btn-resume {
background: linear-gradient(135deg, #10b981 0%, #059669 100%);
color: white;
box-shadow: 0 2px 6px rgba(16, 185, 129, 0.3);
}
.btn-resume:hover {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}
.btn-clear {
background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
color: white;
box-shadow: 0 2px 6px rgba(239, 68, 68, 0.3);
}
.btn-clear:hover {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}
.btn-download {
background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
color: white;
box-shadow: 0 2px 6px rgba(99, 102, 241, 0.3);
}
.btn-download:hover {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}
/* Level Filter */
.filter-buttons {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
.btn-filter {
padding: 8px 16px;
border: 2px solid #e5e7eb;
border-radius: 8px;
font-size: 13px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s;
background: white;
color: #6b7280;
}
.btn-filter:hover {
border-color: #6366f1;
color: #6366f1;
}
.btn-filter.active {
background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
color: white;
border-color: #6366f1;
}
.btn-filter.error.active {
background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
border-color: #ef4444;
}
.btn-filter.warning.active {
background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
border-color: #f59e0b;
}
.btn-filter.info.active {
background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
border-color: #3b82f6;
}
/* Search Box */
.search-box {
position: relative;
flex: 1;
min-width: 250px;
}
.search-box input {
width: 100%;
padding: 10px 40px 10px 40px;
border: 2px solid #e5e7eb;
border-radius: 8px;
font-size: 14px;
transition: all 0.3s;
}
.search-box input:focus {
outline: none;
border-color: #6366f1;
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}
.search-box .search-icon {
position: absolute;
left: 12px;
top: 50%;
transform: translateY(-50%);
color: #9ca3af;
font-size: 14px;
}
.search-box .clear-icon {
position: absolute;
right: 12px;
top: 50%;
transform: translateY(-50%);
color: #9ca3af;
font-size: 14px;
cursor: pointer;
display: none;
}
.search-box.has-text .clear-icon {
display: block;
}
/* Font Size Controls */
.font-size-controls {
display: flex;
gap: 6px;
}
.btn-font-size {
padding: 8px 14px;
border: 2px solid #e5e7eb;
border-radius: 8px;
font-size: 13px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s;
background: white;
color: #6b7280;
}
.btn-font-size:hover {
border-color: #6366f1;
color: #6366f1;
}
.btn-font-size.active {
background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
color: white;
border-color: #6366f1;
}
/* Toggle Switches */
.toggle-group {
display: flex;
gap: 20px;
flex-wrap: wrap;
}
.toggle-item {
display: flex;
align-items: center;
gap: 10px;
}
.toggle-switch {
position: relative;
display: inline-block;
width: 48px;
height: 26px;
}
.toggle-switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(135deg, #d1d5db 0%, #9ca3af 100%);
transition: .4s;
border-radius: 26px;
}
.slider:before {
position: absolute;
content: "";
height: 20px;
width: 20px;
left: 3px;
bottom: 3px;
background: white;
transition: .4s;
border-radius: 50%;
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
input:checked + .slider {
background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}
input:checked + .slider:before {
transform: translateX(22px);
}
.toggle-label {
font-size: 14px;
color: #4b5563;
font-weight: 500;
}
/* Statistics Cards */
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin-bottom: 25px;
}
.stat-card {
background: white;
padding: 20px;
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0,0,0,0.06);
display: flex;
align-items: center;
gap: 15px;
}
.stat-icon {
width: 50px;
height: 50px;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
font-size: 22px;
}
.stat-card.total .stat-icon {
background: linear-gradient(135deg, #e0e7ff 0%, #c7d2fe 100%);
color: #6366f1;
}
.stat-card.error .stat-icon {
background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
color: #ef4444;
}
.stat-card.warning .stat-icon {
background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
color: #f59e0b;
}
.stat-card.info .stat-icon {
background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
color: #3b82f6;
}
.stat-content {
flex: 1;
}
.stat-value {
font-size: 28px;
font-weight: 700;
color: #1f2937;
line-height: 1;
}
.stat-label {
font-size: 12px;
color: #6b7280;
font-weight: 500;
text-transform: uppercase;
letter-spacing: 0.5px;
margin-top: 5px;
}
/* Log Container */
.log-container-wrapper {
background: white;
padding: 0;
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0,0,0,0.06);
overflow: hidden;
}
#log-container {
background-color: #1e1e1e;
color: #d4d4d4;
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
padding: 20px;
height: 65vh;
overflow-y: auto;
overflow-x: auto;
white-space: pre-wrap;
word-wrap: break-word;
font-size: 13px;
line-height: 1.6;
position: relative;
}
#log-container.font-small {
font-size: 11px;
}
#log-container.font-medium {
font-size: 13px;
}
#log-container.font-large {
font-size: 15px;
}
/* Custom Scrollbar */
#log-container::-webkit-scrollbar {
width: 12px;
height: 12px;
}
#log-container::-webkit-scrollbar-track {
background: #2d2d2d;
border-radius: 6px;
}
#log-container::-webkit-scrollbar-thumb {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 6px;
}
#log-container::-webkit-scrollbar-thumb:hover {
background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}
/* Log Line Highlighting */
.log-line {
padding: 2px 0;
border-radius: 3px;
}
.log-line.error {
background: rgba(239, 68, 68, 0.15);
border-left: 3px solid #ef4444;
padding-left: 8px;
margin: 2px 0;
}
.log-line.warning {
background: rgba(245, 158, 11, 0.15);
border-left: 3px solid #f59e0b;
padding-left: 8px;
margin: 2px 0;
}
.log-line.info {
border-left: 3px solid #3b82f6;
padding-left: 8px;
margin: 2px 0;
}
.log-timestamp {
color: #10b981;
font-weight: 600;
}
.log-error {
color: #f87171;
font-weight: 600;
}
.log-warning {
color: #fbbf24;
font-weight: 600;
}
.log-info {
color: #60a5fa;
font-weight: 600;
}
.highlight {
background: rgba(251, 191, 36, 0.4);
padding: 2px 4px;
border-radius: 2px;
}
/* Empty State */
.log-empty {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
color: #6b7280;
}
.log-empty i {
font-size: 64px;
color: #9ca3af;
margin-bottom: 20px;
}
.log-empty p {
font-size: 16px;
margin: 0;
}
/* Toast Notifications */
.toast-container {
position: fixed;
top: 80px;
right: 20px;
z-index: 9999;
}
.toast-notification {
background: white;
padding: 16px 20px;
border-radius: 12px;
box-shadow: 0 10px 25px rgba(0,0,0,0.15);
margin-bottom: 12px;
min-width: 300px;
display: flex;
align-items: center;
gap: 12px;
animation: slideIn 0.3s ease-out;
}
@keyframes slideIn {
from {
transform: translateX(400px);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
.toast-notification.success {
border-left: 4px solid #10b981;
}
.toast-notification.success .toast-icon {
color: #10b981;
}
.toast-notification.error {
border-left: 4px solid #ef4444;
}
.toast-notification.error .toast-icon {
color: #ef4444;
}
.toast-notification.info {
border-left: 4px solid #3b82f6;
}
.toast-notification.info .toast-icon {
color: #3b82f6;
}
.toast-icon {
font-size: 20px;
}
.toast-content {
flex: 1;
}
.toast-message {
color: #1f2937;
font-size: 14px;
font-weight: 500;
}
/* Responsive */
@media (max-width: 768px) {
.page-header {
flex-direction: column;
gap: 15px;
}
.status-indicators {
width: 100%;
justify-content: space-between;
}
.control-buttons {
flex-direction: column;
}
.btn-control {
width: 100%;
}
.stats-grid {
grid-template-columns: 1fr;
}
#log-container {
height: 50vh;
}
}
</style>
</head>
<body>
{% include 'components/_navbar.html' %}
<div class="container">
<!-- Page Header -->
<div class="page-header">
<h4><i class="fas fa-file-alt me-2"></i>系統即時日誌</h4>
<div class="status-indicators">
<div class="status-item">
<div class="status-dot"></div>
<span id="connection-status">連接正常</span>
</div>
<div class="status-item">
<i class="fas fa-clock"></i>
<span id="last-update">最後更新: --</span>
</div>
</div>
</div>
<!-- Statistics Cards -->
<div class="stats-grid">
<div class="stat-card total">
<div class="stat-icon">
<i class="fas fa-list"></i>
</div>
<div class="stat-content">
<div class="stat-value" id="total-lines">0</div>
<div class="stat-label">總行數</div>
</div>
</div>
<div class="stat-card error">
<div class="stat-icon">
<i class="fas fa-times-circle"></i>
</div>
<div class="stat-content">
<div class="stat-value" id="error-count">0</div>
<div class="stat-label">ERROR</div>
</div>
</div>
<div class="stat-card warning">
<div class="stat-icon">
<i class="fas fa-exclamation-triangle"></i>
</div>
<div class="stat-content">
<div class="stat-value" id="warning-count">0</div>
<div class="stat-label">WARNING</div>
</div>
</div>
<div class="stat-card info">
<div class="stat-icon">
<i class="fas fa-info-circle"></i>
</div>
<div class="stat-content">
<div class="stat-value" id="info-count">0</div>
<div class="stat-label">INFO</div>
</div>
</div>
</div>
<!-- Control Panel -->
<div class="control-panel">
<!-- Main Actions -->
<div class="control-section">
<div class="control-section-title">主要操作</div>
<div class="control-buttons">
<button class="btn-control btn-refresh" onclick="refreshLogs()">
<i class="fas fa-sync-alt"></i>
<span>立即刷新</span>
</button>
<button class="btn-control btn-pause" id="pause-btn" onclick="toggleAutoRefresh()">
<i class="fas fa-pause"></i>
<span>暫停自動刷新</span>
</button>
<button class="btn-control btn-clear" onclick="clearLogs()">
<i class="fas fa-eraser"></i>
<span>清除日誌</span>
</button>
<button class="btn-control btn-download" onclick="downloadLogs()">
<i class="fas fa-download"></i>
<span>下載日誌</span>
</button>
</div>
</div>
<!-- Level Filter & Search -->
<div class="control-section">
<div class="control-section-title">過濾與搜尋</div>
<div style="display: flex; gap: 15px; flex-wrap: wrap; align-items: center;">
<div class="filter-buttons">
<button class="btn-filter active" data-level="all" onclick="filterByLevel('all')">
<i class="fas fa-list me-1"></i>ALL
</button>
<button class="btn-filter error" data-level="error" onclick="filterByLevel('error')">
<i class="fas fa-times-circle me-1"></i>ERROR
</button>
<button class="btn-filter warning" data-level="warning" onclick="filterByLevel('warning')">
<i class="fas fa-exclamation-triangle me-1"></i>WARNING
</button>
<button class="btn-filter info" data-level="info" onclick="filterByLevel('info')">
<i class="fas fa-info-circle me-1"></i>INFO
</button>
</div>
<div class="search-box" id="search-box">
<i class="fas fa-search search-icon"></i>
<input type="text" id="search-input" placeholder="搜尋關鍵字..." oninput="searchLogs()">
<i class="fas fa-times clear-icon" onclick="clearSearch()"></i>
</div>
</div>
</div>
<!-- Display Options -->
<div class="control-section" style="margin-bottom: 0;">
<div class="control-section-title">顯示選項</div>
<div style="display: flex; gap: 30px; flex-wrap: wrap; align-items: center;">
<div style="display: flex; gap: 8px; align-items: center;">
<span style="font-size: 13px; color: #6b7280; font-weight: 500;">字體大小:</span>
<div class="font-size-controls">
<button class="btn-font-size" data-size="small" onclick="changeFontSize('small')"></button>
<button class="btn-font-size active" data-size="medium" onclick="changeFontSize('medium')"></button>
<button class="btn-font-size" data-size="large" onclick="changeFontSize('large')"></button>
</div>
</div>
<div class="toggle-group">
<div class="toggle-item">
<label class="toggle-switch">
<input type="checkbox" id="auto-scroll-toggle" checked onchange="toggleAutoScroll()">
<span class="slider"></span>
</label>
<span class="toggle-label">自動滾動</span>
</div>
</div>
</div>
</div>
</div>
<!-- Log Container -->
<div class="log-container-wrapper">
<div id="log-container" class="font-medium">
<div class="log-empty">
<i class="fas fa-file-alt"></i>
<p>正在載入日誌...</p>
</div>
</div>
</div>
</div>
<!-- Toast Container -->
<div class="toast-container" id="toast-container"></div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
// Global state
let autoRefreshEnabled = true;
let autoScrollEnabled = true;
let currentFilter = 'all';
let searchKeyword = '';
let refreshInterval = null;
let rawLogs = '';
// Initialize
document.addEventListener('DOMContentLoaded', function() {
fetchLogs();
startAutoRefresh();
updateNavTime();
setInterval(updateNavTime, 1000);
});
// ===== Utility Functions =====
function showToast(message, type = 'success') {
const container = document.getElementById('toast-container');
const toast = document.createElement('div');
toast.className = `toast-notification ${type}`;
const icon = type === 'success' ? 'check-circle' : type === 'error' ? 'exclamation-circle' : 'info-circle';
toast.innerHTML = `
<div class="toast-icon">
<i class="fas fa-${icon}"></i>
</div>
<div class="toast-content">
<div class="toast-message">${message}</div>
</div>
`;
container.appendChild(toast);
setTimeout(() => {
toast.style.animation = 'slideIn 0.3s ease-out reverse';
setTimeout(() => toast.remove(), 300);
}, 3000);
}
function updateNavTime() {
const now = new Date();
const timeStr = now.toLocaleString('zh-TW', {
year: 'numeric', month: '2-digit', day: '2-digit',
hour: '2-digit', minute: '2-digit', second: '2-digit'
});
document.getElementById('nav-time').textContent = timeStr;
}
function updateLastUpdateTime() {
const now = new Date();
const timeStr = now.toLocaleTimeString('zh-TW');
document.getElementById('last-update').textContent = `最後更新: ${timeStr}`;
}
// ===== Log Fetching and Display =====
function fetchLogs() {
fetch('/api/logs')
.then(response => response.json())
.then(data => {
rawLogs = data.logs || '';
updateStats(rawLogs);
displayLogs();
updateLastUpdateTime();
document.getElementById('connection-status').textContent = '連接正常';
})
.catch(error => {
console.error('Error fetching logs:', error);
document.getElementById('connection-status').textContent = '連接失敗';
showToast('載入日誌失敗', 'error');
});
}
function displayLogs() {
const container = document.getElementById('log-container');
if (!rawLogs || rawLogs.trim() === '') {
container.innerHTML = `
<div class="log-empty">
<i class="fas fa-file-alt"></i>
<p>暫無日誌資料</p>
</div>
`;
return;
}
const lines = rawLogs.split('\n');
let filteredLines = lines;
// Apply level filter
if (currentFilter !== 'all') {
filteredLines = filteredLines.filter(line => {
const upperLine = line.toUpperCase();
if (currentFilter === 'error') return upperLine.includes('ERROR');
if (currentFilter === 'warning') return upperLine.includes('WARNING');
if (currentFilter === 'info') return upperLine.includes('INFO');
return true;
});
}
// Apply search filter
if (searchKeyword) {
filteredLines = filteredLines.filter(line =>
line.toLowerCase().includes(searchKeyword.toLowerCase())
);
}
// Format lines
const formattedLines = filteredLines.map(line => formatLogLine(line)).join('\n');
container.innerHTML = formattedLines || '<div class="log-empty"><i class="fas fa-search"></i><p>沒有符合的日誌</p></div>';
// Auto scroll
if (autoScrollEnabled) {
container.scrollTop = container.scrollHeight;
}
}
function formatLogLine(line) {
if (!line.trim()) return '';
let className = '';
let formatted = line;
// Detect log level
const upperLine = line.toUpperCase();
if (upperLine.includes('ERROR')) {
className = 'error';
formatted = line.replace(/ERROR/gi, '<span class="log-error">ERROR</span>');
} else if (upperLine.includes('WARNING')) {
className = 'warning';
formatted = line.replace(/WARNING/gi, '<span class="log-warning">WARNING</span>');
} else if (upperLine.includes('INFO')) {
className = 'info';
formatted = line.replace(/INFO/gi, '<span class="log-info">INFO</span>');
}
// Highlight timestamps (common patterns)
formatted = formatted.replace(/(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})/g, '<span class="log-timestamp">$1</span>');
formatted = formatted.replace(/(\d{2}:\d{2}:\d{2})/g, '<span class="log-timestamp">$1</span>');
// Highlight search keyword
if (searchKeyword) {
const regex = new RegExp(`(${searchKeyword})`, 'gi');
formatted = formatted.replace(regex, '<span class="highlight">$1</span>');
}
return `<div class="log-line ${className}">${formatted}</div>`;
}
function updateStats(logs) {
const lines = logs.split('\n').filter(line => line.trim());
const totalLines = lines.length;
const errorCount = lines.filter(line => line.toUpperCase().includes('ERROR')).length;
const warningCount = lines.filter(line => line.toUpperCase().includes('WARNING')).length;
const infoCount = lines.filter(line => line.toUpperCase().includes('INFO')).length;
document.getElementById('total-lines').textContent = totalLines;
document.getElementById('error-count').textContent = errorCount;
document.getElementById('warning-count').textContent = warningCount;
document.getElementById('info-count').textContent = infoCount;
}
// ===== Control Functions =====
function refreshLogs() {
const btn = event.target.closest('.btn-refresh');
btn.classList.add('spinning');
btn.disabled = true;
fetchLogs();
setTimeout(() => {
btn.classList.remove('spinning');
btn.disabled = false;
showToast('日誌已刷新', 'success');
}, 600);
}
function toggleAutoRefresh() {
autoRefreshEnabled = !autoRefreshEnabled;
const btn = document.getElementById('pause-btn');
if (autoRefreshEnabled) {
btn.className = 'btn-control btn-pause';
btn.innerHTML = '<i class="fas fa-pause"></i><span>暫停自動刷新</span>';
startAutoRefresh();
showToast('已啟用自動刷新', 'success');
} else {
btn.className = 'btn-control btn-resume';
btn.innerHTML = '<i class="fas fa-play"></i><span>繼續自動刷新</span>';
stopAutoRefresh();
showToast('已暫停自動刷新', 'info');
}
}
function startAutoRefresh() {
if (refreshInterval) clearInterval(refreshInterval);
refreshInterval = setInterval(fetchLogs, 5000);
}
function stopAutoRefresh() {
if (refreshInterval) {
clearInterval(refreshInterval);
refreshInterval = null;
}
}
function clearLogs() {
if (confirm('確定要清除日誌顯示嗎?(不會刪除實際日誌檔案)')) {
rawLogs = '';
updateStats('');
displayLogs();
showToast('已清除日誌顯示', 'success');
}
}
function downloadLogs() {
if (!rawLogs) {
showToast('沒有可下載的日誌', 'error');
return;
}
const blob = new Blob([rawLogs], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
const now = new Date();
const timestamp = now.toISOString().replace(/[:.]/g, '-').slice(0, -5);
a.download = `momo_system_logs_${timestamp}.txt`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
showToast('日誌已下載', 'success');
}
// ===== Filter and Search Functions =====
function filterByLevel(level) {
currentFilter = level;
// Update button states
document.querySelectorAll('.btn-filter').forEach(btn => {
btn.classList.remove('active');
if (btn.dataset.level === level) {
btn.classList.add('active');
}
});
displayLogs();
}
function searchLogs() {
const input = document.getElementById('search-input');
const searchBox = document.getElementById('search-box');
searchKeyword = input.value.trim();
if (searchKeyword) {
searchBox.classList.add('has-text');
} else {
searchBox.classList.remove('has-text');
}
displayLogs();
}
function clearSearch() {
const input = document.getElementById('search-input');
const searchBox = document.getElementById('search-box');
input.value = '';
searchKeyword = '';
searchBox.classList.remove('has-text');
displayLogs();
input.focus();
}
// ===== Display Options =====
function changeFontSize(size) {
const container = document.getElementById('log-container');
// Remove all size classes
container.classList.remove('font-small', 'font-medium', 'font-large');
// Add selected size class
container.classList.add(`font-${size}`);
// Update button states
document.querySelectorAll('.btn-font-size').forEach(btn => {
btn.classList.remove('active');
if (btn.dataset.size === size) {
btn.classList.add('active');
}
});
}
function toggleAutoScroll() {
autoScrollEnabled = document.getElementById('auto-scroll-toggle').checked;
if (autoScrollEnabled) {
const container = document.getElementById('log-container');
container.scrollTop = container.scrollHeight;
}
}
</script>
</body>
</html>