|
| 1 | +"use client" |
| 2 | +import TitleBar from '../../components/TitleBar' |
| 3 | +import { useState } from 'react' |
| 4 | + |
| 5 | +export default function LogsPage () { |
| 6 | + // Static mock data for demonstration |
| 7 | + const mockEntries = [ |
| 8 | + { timestamp: '2025-09-11T10:00:00.000Z', level: 'INFO', message: 'Safe Settings service started.' }, |
| 9 | + { timestamp: '2025-09-11T10:01:05.123Z', level: 'WARN', message: 'Config file missing, using defaults.' }, |
| 10 | + { timestamp: '2025-09-11T10:02:10.456Z', level: 'ERROR', message: 'Failed to sync settings: network error.' }, |
| 11 | + { timestamp: '2025-09-11T10:03:00.789Z', level: 'DEBUG', message: 'Polling GitHub API for updates.' }, |
| 12 | + { timestamp: '2025-09-11T10:04:15.000Z', level: 'INFO', message: 'Sync completed successfully.' }, |
| 13 | + { timestamp: '2025-09-11T10:05:00.000Z', level: 'INFO', message: 'SYNC: Organization settings updated.' }, |
| 14 | + { timestamp: '2025-09-11T10:06:00.000Z', level: 'ERROR', message: 'SYNC: Failed to update organization settings.' } |
| 15 | + ] |
| 16 | + |
| 17 | + const logLevels = ['INFO', 'WARN', 'DEBUG', 'ERROR'] |
| 18 | + const [selectedLevels, setSelectedLevels] = useState(new Set(logLevels)) |
| 19 | + const [search, setSearch] = useState('') |
| 20 | + |
| 21 | + const toggleLevel = (lvl) => { |
| 22 | + const next = new Set(selectedLevels) |
| 23 | + if (next.has(lvl)) next.delete(lvl) |
| 24 | + else next.add(lvl) |
| 25 | + setSelectedLevels(next) |
| 26 | + } |
| 27 | + |
| 28 | + const filtered = mockEntries.filter(e => |
| 29 | + selectedLevels.has(e.level.toUpperCase()) && |
| 30 | + (search.trim() === '' || e.message.toLowerCase().includes(search.trim().toLowerCase())) |
| 31 | + ) |
| 32 | + |
| 33 | + return ( |
| 34 | + <> |
| 35 | + <TitleBar /> |
| 36 | + <div className="container py-4"> |
| 37 | + <div className="col-12 mb-4"> |
| 38 | + <div className="card shadow-sm"> |
| 39 | + <div className="card-body"> |
| 40 | + <h4 className="card-title mb-2">Safe Settings Log</h4> |
| 41 | + <p className="card-text text-muted">View recent log entries for Safe Settings operations and syncs.</p> |
| 42 | + </div> |
| 43 | + </div> |
| 44 | + </div> |
| 45 | + <div className="col-12 mb-4"> |
| 46 | + <div className="card shadow-sm"> |
| 47 | + <div className="card-body"> |
| 48 | + <h5 className="card-title mb-3">Filter Options</h5> |
| 49 | + <div className="mb-2"> |
| 50 | + <strong>Log Levels:</strong> |
| 51 | + <div className="d-flex gap-3 mt-2"> |
| 52 | + {logLevels.map(lvl => ( |
| 53 | + <label key={lvl} className="form-check form-check-inline"> |
| 54 | + <input className="form-check-input" type="checkbox" checked={selectedLevels.has(lvl)} onChange={() => toggleLevel(lvl)} /> |
| 55 | + <span className="form-check-label">{lvl}</span> |
| 56 | + </label> |
| 57 | + ))} |
| 58 | + </div> |
| 59 | + </div> |
| 60 | + <div className="mt-3"> |
| 61 | + <strong>Search Message:</strong> |
| 62 | + <input |
| 63 | + type="text" |
| 64 | + className="form-control mt-1" |
| 65 | + placeholder="Search for SYNC, error, etc." |
| 66 | + value={search} |
| 67 | + onChange={e => setSearch(e.target.value)} |
| 68 | + style={{ maxWidth: 300 }} |
| 69 | + /> |
| 70 | + </div> |
| 71 | + </div> |
| 72 | + </div> |
| 73 | + </div> |
| 74 | + <div className="col-12"> |
| 75 | + <div className="card shadow-sm"> |
| 76 | + <div className="card-body"> |
| 77 | + <h5 className="card-title mb-3">Log Entries</h5> |
| 78 | + <div className="table-responsive" style={{ maxHeight: '60vh', overflow: 'auto' }}> |
| 79 | + <table className="table table-sm table-striped align-middle"> |
| 80 | + <thead> |
| 81 | + <tr> |
| 82 | + <th style={{width: '200px'}}>Timestamp</th> |
| 83 | + <th style={{width: '90px'}}>Level</th> |
| 84 | + <th>Message</th> |
| 85 | + </tr> |
| 86 | + </thead> |
| 87 | + <tbody> |
| 88 | + {filtered.map((row, i) => { |
| 89 | + let levelClass = '' |
| 90 | + if (row.level === 'ERROR') levelClass = 'log-error' |
| 91 | + else if (row.level === 'WARN') levelClass = 'log-warn' |
| 92 | + return ( |
| 93 | + <tr key={`${row.timestamp || 'na'}-${i}`}> |
| 94 | + <td style={{fontSize: '0.85rem', whiteSpace: 'nowrap'}}>{row.timestamp || '-'}</td> |
| 95 | + <td className={levelClass} style={{fontWeight: 600}}>{row.level || 'UNKNOWN'}</td> |
| 96 | + <td className={levelClass} style={{fontFamily: 'monospace', fontSize: '0.9rem', whiteSpace: 'pre-wrap'}}>{row.message}</td> |
| 97 | + </tr> |
| 98 | + ) |
| 99 | + })} |
| 100 | + </tbody> |
| 101 | + </table> |
| 102 | + {filtered.length === 0 && <div className="text-muted py-3">No log entries match your filters.</div>} |
| 103 | + </div> |
| 104 | + </div> |
| 105 | + </div> |
| 106 | + </div> |
| 107 | + </div> |
| 108 | + </> |
| 109 | + ) |
| 110 | +} |
0 commit comments