Skip to main content

Stream log files and extract context/blocks around spanId matches.

Project description

logs-spectre

                              __                  
  ____________   ____   _____/  |________   ____  
 /  ___/\____ \_/ __ \_/ ___\   __\_  __ \_/ __ \ 
 \___ \ |  |_> >  ___/\  \___|  |  |  | \/\  ___/ 
/____  >|   __/ \___  >\___  >__|  |__|    \___  >
     \/ |__|        \/     \/                  \/ 

logs-spectre or spectre is a lightweight command-line tool that searches large log files for a given span ID and extracts either:

  • Context around the match (like grep -C), or\
  • The full logical log block (including multiline stack traces)

It is designed for troubleshooting distributed systems and observability workflows, especially when following traces across services.


Why logs-spectre?

When debugging production systems, you often need to:

  • Follow a single request across multiple services
  • Extract stack traces tied to a specific span
  • Search very large log files safely
  • Avoid loading entire files into memory

logs-spectre solves this efficiently with streaming, zero external dependencies, and a simple CLI interface.


Installation

Install from PyPI:

pip install logs-spectre

After installation, use the CLI command:

spectre

Quick Start

Search for a span ID in a log file:

spectre --logfile app.log --spanid F76281848BD8288C

Show the full logical block (including stack traces):

spectre --logfile app.log --spanid F76281848BD8288C --mode block

Write results to a file:

spectre --logfile app.log --spanid F76281848BD8288C --output result.log

Supported Log Formats

1. Key-Value / Plain Text Logs

Supports variations like:

  • spanId=...
  • span_id=...
  • span-id=...
  • spanid=...

2. JSON Logs (one entry per line)

Extracts span IDs from fields such as:

  • spanId
  • span_id
  • spanid
  • span-id

3. W3C traceparent Format

Example:

traceparent="00-<trace-id>-<parent-id>-<flags>"

The parent-id (16 hex characters) is treated as the span ID.


Usage

spectre --logfile PATH --spanid VALUE [options]

Required Arguments

  • --logfile PATH --- Path to the log file\
  • --spanid VALUE --- Span ID to search for

Optional Arguments

  • --context N --- Number of lines before and after match (default: 20)\
  • --mode {context,block}
    • context → N lines before + match + N lines after\
    • block → Full logical block including multiline stack traces\
  • --output PATH --- Write results to a file instead of stdout\
  • --format {auto,kv,json,traceparent} --- Force format detection (default: auto)\
  • --ignore-case (default) --- Case-insensitive matching\
  • --case-sensitive --- Enable case-sensitive matching\
  • --interactive --- Prompt for missing arguments interactively

Output Format

For each match:

===== MATCH <index> START =====
line: <file line number>
spanId: <matching span id>
<extracted lines...>
===== MATCH <index> END =====

Exit Codes

  • 0 → Match found\
  • 1 → No match found\
  • 2 → File error (not found / permission issue)

Performance

  • Streams files line-by-line (safe for very large logs)
  • Uses a fixed-size ring buffer for context lines
  • Avoids loading entire files into memory
  • Dependency-free runtime

Requirements

  • Python 3.11+

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

logs_spectre-0.1.3.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

logs_spectre-0.1.3-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file logs_spectre-0.1.3.tar.gz.

File metadata

  • Download URL: logs_spectre-0.1.3.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for logs_spectre-0.1.3.tar.gz
Algorithm Hash digest
SHA256 09bffab4451378c94c128c784c26785948bdd33967b0452a4bd809653fce3c5d
MD5 9a676c97fbd7348e0ab71999c1cf67f8
BLAKE2b-256 eeb339241c8080cd36ad9cdac71d01314c7a6b22027e5c0da31c60f57662192f

See more details on using hashes here.

File details

Details for the file logs_spectre-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: logs_spectre-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for logs_spectre-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 505a068e8ea22053531011794ea9ca77d8272c1740b9f0eb30bf1ccdbbe73056
MD5 604fc568b35cabf03c3ed80cd2252279
BLAKE2b-256 922f06120e1c57d2bd66f17a93e58a6fec54a0bbaf848bc093716d12dacb1c5b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page