HTML Log Viewer: Separate Matches from Context

HTML for this example

Select the code and use your copy shortcut. Changes in this preview are temporary.

<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>HTML Log Viewer: Separate Matches from Context</title><style>*{box-sizing:border-box}body{margin:0;color:var(--ink,#233342);background:var(--bg,#eef2f3);font:17px/1.6 system-ui,sans-serif}main{max-width:980px;margin:auto;padding:clamp(16px,4vw,38px)}h1{font:700 clamp(30px,5vw,49px)/1.12 Georgia,serif;margin:10px 0 20px;max-width:800px}h2{font-size:24px;line-height:1.3;margin:0 0 15px}h3{font-size:19px;margin:12px 0}p{margin:0 0 16px}.eyebrow{font-weight:750;letter-spacing:.08em;text-transform:uppercase;font-size:16px}header{padding:10px 0 25px;border-bottom:3px solid var(--accent,#24586d);margin-bottom:24px}.lede{font-size:20px;max-width:760px}.panel{background:var(--paper,#fff);padding:clamp(18px,3vw,28px);border:1px solid var(--line,#c6d1d8);border-radius:12px;margin:20px 0}.grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:20px}.grid>*{min-width:0}.row{display:flex;gap:12px;flex-wrap:wrap;align-items:center;margin:16px 0}.stack>*{margin:12px 0}button{font:700 17px/1.4 system-ui,sans-serif;cursor:pointer;color:white;background:var(--accent,#24586d);border:2px solid var(--accent,#24586d);border-radius:7px;padding:11px 17px;max-width:100%;overflow-wrap:anywhere}button.secondary{background:transparent;color:var(--ink,#233342)}button[aria-pressed=true]{box-shadow:inset 0 0 0 3px #fff;outline:2px solid var(--ink,#233342)}button:disabled{opacity:.55;cursor:default}input,textarea,select{font:17px/1.5 system-ui,sans-serif;color:inherit;background:white;border:1px solid #778591;padding:10px 12px;border-radius:6px;max-width:100%;width:100%;min-width:0}input[type=checkbox]{width:22px;height:22px}textarea{min-height:110px;resize:vertical}label{display:block;font-weight:700;margin:12px 0 7px}button:focus-visible,input:focus-visible,textarea:focus-visible,summary:focus-visible,[tabindex]:focus-visible{outline:3px solid #aa3d70;outline-offset:4px}.result{padding:18px;border-left:5px solid var(--accent,#24586d);background:var(--soft,#e5eff2);white-space:pre-wrap;overflow-wrap:anywhere;margin:20px 0}.result:empty{display:none}.hint{font-size:16px;color:var(--muted,#435968)}table{border-collapse:collapse;width:100%;table-layout:fixed;margin:16px 0}th,td{text-align:left;vertical-align:top;overflow-wrap:anywhere;padding:12px 8px;border-bottom:1px solid var(--line,#c6d1d8)}caption{text-align:left;font-weight:750;margin:8px 0}details{padding:18px;border:1px dashed #7b8b96;margin:20px 0}summary{cursor:pointer;font-weight:750}pre{font:16px/1.6 ui-monospace,monospace;white-space:pre-wrap;overflow-wrap:anywhere;background:#162735;color:#f5f8fa;padding:18px;border-radius:8px}canvas,svg{display:block;max-width:100%;height:auto}footer{margin:28px 0;font-size:16px}.badge{font-weight:750;color:var(--accent,#24586d)}.metric{font:700 38px/1.3 Georgia,serif}.board{display:grid;gap:5px;max-width:440px;margin:20px auto}.board button{padding:7px;min-height:45px}.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}@media(max-width:560px){.grid{grid-template-columns:1fr}main{padding:16px}th,td{padding:10px 5px}.row button{flex-grow:1}.metric{font-size:32px}}
:root{--bg:#14232b;--paper:#20353f;--ink:#f1f5f7;--accent:#2b7484;--soft:#153e47;--line:#4a626b;--muted:#d0dce1}input,textarea{background:#f8fbfc;color:#172a33}pre{background:#0b1920;min-height:100px}.logrows{font:16px/1.8 ui-monospace,monospace;white-space:pre-wrap}</style></head><body><main><header><p class="eyebrow">Excerpt inspector · Paste only</p><h1>HTML Log Viewer: Separate Matches from Context</h1><p class="lede">One error match can produce three visible rows when its neighbors are included.</p><p class="hint">Local excerpt inspection only. Do not paste sensitive logs into a shared explanation. No upload, storage, tailing, export or automatic redaction.</p></header><section class="panel"><h2>Original excerpt</h2><label for="raw">Log text, up to 20,000 code units and 500 records</label><textarea id="raw" rows="6">[INFO] started
[ERROR] failed request r1
  at worker:12
[INFO] ended</textarea><div class="row"><button id="inspect" type="button">Inspect excerpt</button><button id="clear" type="button" class="secondary">Clear input</button></div></section><section class="panel"><h2>Filter the inspected records</h2><div class="row"><button id="levelDEBUG" type="button" aria-pressed="true">DEBUG</button><button id="levelINFO" type="button" aria-pressed="true">INFO</button><button id="levelWARN" type="button" aria-pressed="true">WARN</button><button id="levelERROR" type="button" aria-pressed="true">ERROR</button><button id="levelUNKNOWN" type="button" aria-pressed="true">UNKNOWN</button></div><div class="row"><button id="errorsOnly" type="button">Errors only</button><button id="all" type="button">All levels</button><button id="context" type="button" aria-pressed="false">Show ±1 context</button><button id="resetFilters" type="button">Reset filters</button></div><label for="query">Literal message search</label><input id="query"><p id="counts" class="result" role="status">Inspect an excerpt first.</p><pre id="rows" class="logrows"></pre><label for="line">Original line number to inspect</label><input id="line" inputmode="numeric"><button id="detailButton" type="button">Inspect line</button><pre id="detail"></pre></section><footer>Keep any records you need in your own working files. This page makes no network requests and saves no responses.</footer></main><script>
(()=>{'use strict';const $=id=>document.getElementById(id);
let records=[],valid=false,context=false;const levels=['DEBUG','INFO','WARN','ERROR','UNKNOWN'];let selected=new Set(levels);function render(){for(const l of levels)$('level'+l).setAttribute('aria-pressed',String(selected.has(l)));$('context').setAttribute('aria-pressed',String(context));$('detail').textContent='';$('line').value='';if(!valid)return;$('detail').textContent='No original line selected.';const q=$('query').value.toLowerCase(),matches=records.filter(r=>selected.has(r.level)&&r.message.toLowerCase().includes(q));const primary=new Set(matches.map(r=>r.index)),visible=new Set(primary);if(context)for(const n of primary)for(const k of [n-1,n+1])if(k>=0&&k<records.length)visible.add(k);$('counts').textContent=matches.length+' primary matches; '+visible.size+' visible rows.';$('rows').textContent=[...visible].sort((a,b)=>a-b).map(n=>(n+1)+' ['+(primary.has(n)?'MATCH':'CONTEXT ONLY')+'] '+records[n].raw).join('\n');}function inspect(){records=[];valid=false;$('rows').textContent='';$('detail').textContent='';$('line').value='';const raw=$('raw').value;if(raw.length>20000){$('counts').textContent='Excerpt exceeds 20000 code units.';return;}const lines=raw===''?[]:raw.split(/\r?\n/);if(raw.endsWith('\n'))lines.pop();if(lines.length>500){$('counts').textContent='Excerpt exceeds 500 line records.';return;}records=lines.map((raw,index)=>{const m=raw.match(/^\[(DEBUG|INFO|WARN|ERROR)\]/);return{index,raw,level:m?m[1]:'UNKNOWN',message:m?raw.slice(m[0].length):raw};});valid=true;render();}$('inspect').addEventListener('click',inspect);$('raw').addEventListener('input',()=>{valid=false;records=[];$('counts').textContent='Excerpt changed. Inspect again.';$('rows').textContent='';$('detail').textContent='';$('line').value='';});for(const l of levels)$('level'+l).addEventListener('click',()=>{if(selected.has(l))selected.delete(l);else selected.add(l);render();});$('errorsOnly').addEventListener('click',()=>{selected=new Set(['ERROR']);render();});$('all').addEventListener('click',()=>{selected=new Set(levels);render();});$('context').addEventListener('click',()=>{context=!context;render();});$('query').addEventListener('input',render);$('resetFilters').addEventListener('click',()=>{selected=new Set(levels);context=false;$('query').value='';$('line').value='';render();});$('clear').addEventListener('click',()=>{$('raw').value='';records=[];valid=false;$('rows').textContent='';$('counts').textContent='';$('detail').textContent='';$('line').value='';$('query').value='';$('line').value='';});$('detailButton').addEventListener('click',()=>{const raw=$('line').value.trim();if(!valid||!/^\d+$/.test(raw)||Number(raw)<1||Number(raw)>records.length){$('detail').textContent='Choose an existing original line from an inspected excerpt.';return;}const n=Number(raw)-1;$('detail').textContent=records.slice(Math.max(0,n-1),Math.min(records.length,n+2)).map(r=>(r.index+1)+': '+r.raw).join('\n');});
})();
</script></body></html>