Expand description
Parser for FreeSWITCH log files.
Handles the full complexity of mod_logfile output: five distinct line
formats, multi-line CHANNEL_DATA and SDP dumps, truncated buffer collisions,
and per-session state tracking — all with zero dependencies and no regex.
§Architecture
The parser is organized in three composable layers, each wrapping the previous:
- Layer 1 (
parse_line) — stateless, zero-allocation single-line classifier - Layer 2 (
LogStream) — structural state machine that groups continuations, classifies messages, and detects multi-line blocks - Layer 3 (
SessionTracker) — per-UUID state machine that propagates dialplan context, channel state, and variables across entries
See docs/design-rationale.md in the repository for the full story on format
discovery, parsing strategy, and why each layer exists.
§Examples
Read lines from stdin, process through all three layers, and print enriched entries:
use std::io::{self, BufRead};
use freeswitch_log_parser::{LogStream, SessionTracker};
let lines = io::stdin().lock().lines().map(|l| l.expect("read error"));
let stream = LogStream::new(lines);
let mut tracker = SessionTracker::new(stream);
for enriched in tracker.by_ref() {
let e = &enriched.entry;
println!("{} [{}] {}", e.timestamp, e.message_kind, e.message);
}
let stats = tracker.stats();
eprintln!("{} lines, {} unclassified",
stats.lines_processed, stats.lines_unclassified);§Feature flags
cli— enables thefslogbinary with clap, xz decompression, and regex filtering
Structs§
- Attached
Lines - Compact storage for the raw continuation lines of a log entry.
- Attached
Lines Iter - Iterator over the lines of an
AttachedLines. - Enriched
Entry - A
LogEntrypaired with the session’s state snapshot at that point in time. - LogEntry
- A complete parsed log entry with all context resolved.
- LogStream
- Layer 2 structural state machine — groups continuation lines, classifies messages, and detects multi-line blocks (CHANNEL_DATA, SDP, codec negotiation).
- Parse
Level Error - Returned when a string doesn’t match any known log level.
- Parse
Stats - Cumulative parsing statistics, updated as lines flow through the stream.
- RawLine
- Zero-copy result of parsing a single log line.
- Segment
Tracker - Handle for looking up which segment a line number belongs to.
- Session
Snapshot - Immutable point-in-time copy of a session’s state, attached to each
EnrichedEntry. - Session
State - Mutable per-UUID state accumulator, updated as entries are processed.
- Session
Tracker - Layer 3 per-session state machine — tracks per-UUID state (dialplan context,
channel state, variables) across entries and yields
EnrichedEntryvalues. - Tracked
Chain - Iterator that concatenates named segments and tracks which line number
each segment starts at. Pair with
SegmentTrackerto look up which segment a given line belongs to. - Unclassified
Line - Record of a single unclassified line, captured when tracking is enabled.
Enums§
- Block
- Structured data extracted from a multi-line dump that follows a primary log entry.
- Call
Direction - Call direction from the
Call-Directionheader. Wire format is lowercase. - Call
State - Call state from
switch_channel_callstate_t— carried in theChannel-Call-Stateheader. - Channel
State - Channel state from
switch_channel_state_t— carried in theChannel-Stateheader as a string (CS_ROUTING) and inChannel-State-Numberas an integer. - Channel
Variable - Core FreeSWITCH channel variable names (the part after the
variable_prefix). - Line
Kind - Classification of a single log line’s structural format.
- LogLevel
- FreeSWITCH log severity level.
- Message
Kind - Semantic classification of a log message’s content.
- SdpDirection
- Which end of a call an SDP body belongs to.
- SipInvite
Direction - Direction of a sofia SIP INVITE log line.
- Sofia
Variable - mod_sofia / SIP channel variable names (the part after the
variable_prefix). - Unclassified
Reason - Why a line was marked as unclassified.
- Unclassified
Tracking - Controls how much detail is recorded for lines that couldn’t be fully classified.
Functions§
- classify_
message - Classify a log message’s text into a
MessageKind. - parse_
line - Layer 1 entry point: classify a single line and extract its fields.