freeswitch_log_parser/lib.rs
1//! Parser for FreeSWITCH log files.
2//!
3//! Handles the full complexity of `mod_logfile` output: five distinct line
4//! formats, multi-line CHANNEL_DATA and SDP dumps, truncated buffer collisions,
5//! and per-session state tracking — no regex, a single dependency
6//! (`freeswitch-types`).
7//!
8//! # Architecture
9//!
10//! The parser is organized in three composable layers, each wrapping the previous:
11//!
12//! - **Layer 1** ([`parse_line`]) — stateless, zero-allocation single-line classifier
13//! - **Layer 2** ([`LogStream`]) — structural state machine that groups continuations,
14//! classifies messages, and detects multi-line blocks
15//! - **Layer 3** ([`SessionTracker`]) — per-UUID state machine that propagates
16//! dialplan context, channel state, and variables across entries; extensible
17//! via [`SessionTracker::with_pre_hook`] and [`SessionTracker::with_post_hook`]
18//! for custom leg detection
19//!
20//! See `docs/design-rationale.md` in the repository for the parsing strategy
21//! and why each layer exists; the line-format anatomy lives in the repository's
22//! CLAUDE.md.
23//!
24//! # Examples
25//!
26//! Read lines from stdin, process through all three layers, and print enriched entries:
27//!
28//! ```no_run
29//! use std::io;
30//! use freeswitch_log_parser::{read_log_lines, LogStream, SessionTracker};
31//!
32//! // read_log_lines tolerates mod_logfile's truncated codepoints; the strict
33//! // BufRead::lines() reader would panic on them.
34//! let lines = read_log_lines(io::stdin().lock()).map(|d| d.expect("read error").text);
35//! let stream = LogStream::new(lines);
36//! let mut tracker = SessionTracker::new(stream);
37//!
38//! for enriched in tracker.by_ref() {
39//! let e = &enriched.entry;
40//! println!("{} [{}] {}", e.timestamp, e.message_kind, e.message);
41//! }
42//!
43//! let stats = tracker.stats();
44//! eprintln!("{} lines, {} unclassified",
45//! stats.lines_processed, stats.lines_unclassified);
46//! ```
47//!
48//! # Feature flags
49//!
50//! - **`cli`** — enables the `fslog` binary with clap, xz decompression, and regex filtering
51
52mod attached;
53mod chain;
54mod codec;
55mod decode;
56mod fields;
57mod level;
58mod line;
59mod message;
60mod peer;
61mod session;
62mod stamp;
63mod stream;
64mod uuid;
65
66pub use attached::{AttachedLines, AttachedLinesIter, AttachedOverflow};
67pub use chain::{SegmentTracker, TrackedChain};
68pub use codec::{CodecMedia, CodecOffer, CodecParseError};
69pub use decode::{
70 classify_utf8, decode_log_line, read_log_lines, truncate_at_char_boundary, DecodedLine,
71 Utf8Decode,
72};
73pub use fields::{
74 apply_fields, message_fields, Field, FieldKind, FieldLocation, RenderError, RenderedEntry,
75};
76pub use freeswitch_types::{
77 variables::{ConferenceVariable, SofiaVariable, VariableName},
78 CallDirection, CallState, ChannelState, ChannelVariable, HangupCause,
79};
80pub use level::{LogLevel, ParseLevelError};
81pub use line::{parse_line, LineKind, RawLine};
82pub use message::{classify_message, DtmfSource, MessageKind, SdpDirection, SipInviteDirection};
83pub use peer::{
84 for_each_peer_uuid, for_each_peer_uuid_with, is_peer_uuid_var, LOOPBACK_PEER_UUID_VARS,
85 PEER_UUID_VARS,
86};
87pub use session::{
88 conference::ConferenceMembership,
89 media::{CodecImpl, MediaCodecs, SessionMedia},
90 parse_bridge_args, BridgeInfo, EnrichedEntry, SessionSnapshot, SessionState, SessionTracker,
91};
92pub use stamp::{log_rotation_stamp, normalize_entry_timestamp};
93pub use stream::{
94 Block, LogEntry, LogStream, ParseStats, ParseWarning, SessionReading, UnclassifiedLine,
95 UnclassifiedReason, UnclassifiedTracking,
96};
97pub use uuid::{find_uuids, is_uuid, FindUuids};