Commit c68a1c9
authored
feat(view-browser): add /log scan-log viewer with level + search filters (#107)
* feat(view-browser): add /log scan-log viewer with level + search filters
Adds a read-only `/log` route to the browser interface that surfaces
the per-run `argus.log` file with the same shape as `/findings`:
filter bar (min level + substring search) above a scrollable
monospace pane, all driven by URL query params so the page stays
bookmarkable.
Closes a real triage gap. Today, answering "why did osv exclude 258
findings?" or "did clamav actually run?" required dropping back to
the terminal and grepping the log; the browser interface had no way
to inspect log output at all. Particularly costly for the personas
this surface targets (owners, managers, execs) who don't keep a
terminal open alongside.
What's in this PR
- `argus/viewers/browser/log_view.py` — UI-free parser + filter
helpers. Mirrors the pattern in `argus.core.findings_view` so
routes, templates, and tests share one code path. Handles
continuation lines (multi-line scanner stderr) by joining onto the
previous header entry.
- `/log` route on the browser app: `?scan=`, `?level=`, `?q=`. Level
filter accepts DEBUG / INFO / WARNING (or short WARN) / ERROR /
CRITICAL, case-insensitive; unrecognized values silently fall back
to "no filter" rather than 500ing on a crafted URL.
- `/log/raw` companion route that streams the file as
`text/plain` with a `Content-Disposition: attachment` header so
browsers download for grep/diff/issue-paste workflows.
- `templates/log.html.j2` plus a `Log` link added to every page's
nav. CSS for `.log-pane` / `.log-level-*` accents (DEBUG muted,
INFO accent-dim, WARN amber, ERROR red) — restrained so a 30k-line
log doesn't look like a Christmas tree.
- 27-test suite in `argus/tests/viewers/browser/test_log.py`:
parser (header lines, continuations, line-number tracking, edge
cases), filter (min level matrix, search case-insensitivity,
combined filters), routes (empty states, level filter, search
filter, scan-param threading through nav, raw download).
Engine: rewords the "Native pull failed for X — retrying with
--platform linux/amd64" log line. The retry virtually always
succeeds for upstreams that publish amd64-only (clamav being the
canonical example), so the line read more alarming than it deserved.
New phrasing: `X: native pull unsuccessful (Nms) — auto-falling
back to --platform linux/amd64 (common for upstreams without arm64
builds)`.
Roadmap (`docs/developer/SDK-ROADMAP.md`): adds Phase 3 — Scan log
viewer with the five tasks (SU through SY) checked off in this PR.
Out-of-scope follow-ups (per-scanner filter chips, jump-to-error
shortcuts, `<mark>` highlighting, live tail) listed there too.
Out of scope for this MVP
- Live tail (deliberately deferred — needs a websocket and process
watcher; out of proportion for a single-user localhost UI)
- Match highlighting via `<mark>` tags (filter narrowing + browser
Cmd+F covers the current pain)
- Per-scanner filter chips
- Jump-to-first-error / jump-to-last-error keyboard shortcuts
Testing
- Full SDK suite: 1390 passed, 8 skipped, 7 deselected (+27 from
the new test_log.py)
- Manual run: `argus scan supply-chain` → `argus view --interface=
browser`, click `Log` in the nav, level filter / search work
end-to-end on the live argus.log file.
* fix(view-browser): parse argus.log as JSON-lines, not plain text
The /log viewer's parser assumed argus.log used the same human-
readable text format the *console* handler emits (HH:MM:SS LEVEL
logger msg). It doesn't — the *file* handler in
``argus.audit.logger.JsonLogFormatter`` writes structured JSON,
one object per line. So the regex matched zero lines on every real
log file and the viewer rendered an empty pane.
Empirical: a real 11KB scan log (45 entries) parsed as 0 entries
before, 45 after.
Rewrites parse_log to read JSON-lines:
- One ``json.loads`` per line; malformed lines (partial flushes,
e.g. when reading a log mid-scan) silently skipped rather than
500ing.
- Records with a non-Python-logging ``level`` are dropped instead
of being assigned an arbitrary rank that would warp filters.
- ``_extract_time`` pulls HH:MM:SS from the ISO timestamp; tolerant
of microseconds and any TZ form (``+00:00``, ``-05:00``, ``Z``).
- The continuation-line concept that mattered for plain-text logs is
gone — multi-line messages live inside the JSON ``message`` string
and the ``<pre>`` template renders embedded newlines as-is.
Tests: replaced the regex-format ``_SAMPLE_LOG`` with a JSON-lines
fixture that mirrors what JsonLogFormatter actually writes, and
added new parser cases for the JSON-specific edge paths (malformed
lines skipped, unknown levels dropped, missing module falls back to
"argus", Z-suffix timestamp, empty lines ignored). 31 tests pass
(up from 27).
LogEntry's display shape is unchanged so the template needs no
edits — only the format being parsed changed.
---------
Co-authored-by: eFAILution <eFAILution@users.noreply.github.com>1 parent a3ad04a commit c68a1c9
8 files changed
Lines changed: 816 additions & 2 deletions
File tree
- argus
- core
- tests/viewers/browser
- viewers/browser
- static
- templates
- docs/developer
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
538 | 538 | | |
539 | 539 | | |
540 | 540 | | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
541 | 545 | | |
542 | | - | |
543 | | - | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
544 | 549 | | |
545 | 550 | | |
546 | 551 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
0 commit comments