Skip to content

feat: add log file support and rendering optimisations#14

Open
neilmartin83 wants to merge 1 commit intomacadmins:mainfrom
neilmartin83:nm-log-support-speed-optimisations
Open

feat: add log file support and rendering optimisations#14
neilmartin83 wants to merge 1 commit intomacadmins:mainfrom
neilmartin83:nm-log-support-speed-optimisations

Conversation

@neilmartin83
Copy link
Copy Markdown
Contributor

Summary

Adds QuickLook preview support for log files (.log, .out, .err) with
heuristic-based syntax highlighting. Since log files have no consistent format,
the tokenizer uses pattern matching to colorize the most common elements that
make logs scannable at a glance.

Also speeds up rendering of large files.

image image image image

What's highlighted

Element Examples Color
Timestamps 2025-09-16 06:20:56 +0100, Mar 28 14:05:33, Apache CLF Muted (italic)
FATAL / CRITICAL / ALERT FATAL, CRITICAL: Bold red
ERROR ERROR, ERROR: Bold red
WARNING WARN, WARNING: Orange
INFO / NOTICE INFO, INFO: Blue
DEBUG / TRACE DEBUG, VERBOSE Muted (italic)
IPv4 addresses 192.168.1.100 Green
HTTP methods GET, POST, DELETE Purple
HTTP status codes 200 (green), 404 (orange), 500 (red) By class
Double-quoted strings "disk space low" String color
File paths /usr/local/etc/config.yaml Variable color
Numbers with units 512MB, 30s, 94% Green

Single quotes are intentionally not treated as string delimiters — apostrophes
in natural log text (JWT's, doesn't) are far too common.

Performance

Log files can be large (2MB+), so three optimizations were made:

  • Line-by-line tokenization for .log — avoids O(n²) regex scanning over
    the entire file by processing each line independently
  • escapeHTML rewritten as a single-pass character scan (was 4 chained
    replacingOccurrences calls, benefiting all formats)
  • renderTokens uses a pre-allocated buffer instead of map + joined
  • Truncation at ~500KB for all formats, with a
    "⋯ Preview truncated (X of Y lines shown)" notice

Files changed (8 files, +306 −23)

  • Shared/SyntaxHighlighter.swift.log format, tokenizer, perf improvements, truncation
  • PiquePreview/Info.plist — UTI, QLSupportedContentTypes, QLFileExtensions
  • PiquePreview/PreviewProvider.swift — format name mapping
  • Pique/Info.plist — UTI declaration
  • Pique/ContentView.swift — Log badge
  • Pique/SettingsView.swift — Log in appearance settings
  • PiqueTests/FileFormatTests.swift — extension mapping + case insensitivity
  • PiqueTests/HighlightIntegrationTests.swift — 15 new tests

Tests

137 total, 0 failures. New tests cover:

  • Severity levels (all tiers, with and without colon)
  • Timestamps (ISO 8601, syslog)
  • IPv4 addresses, HTTP methods, status code coloring by class
  • File paths, double-quoted strings
  • Apostrophe safety (JWT's not treated as string)
  • Multi-line preservation
  • Truncation for large inputs
  • No truncation for small inputs
  • Case-insensitive extension mapping (.LOG)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant