Expand description
Log context extraction — finds keyword-matching lines and captures surrounding context windows for LLM-friendly log triage.
The extractor scans sanitized output line-by-line for any configured keyword (substring match). For each hit it records the matching line, up to N lines of context before and after, and the 1-based line number so engineers can locate the entry in the original file.
§Example
use sanitize_engine::log_context::{LogContextConfig, extract_context};
let log = "INFO start\nERROR disk full\nINFO retrying\nINFO done";
let config = LogContextConfig::new().with_context_lines(1);
let result = extract_context(log, &config);
assert_eq!(result.match_count, 1);
assert_eq!(result.matches[0].line_number, 2);
assert_eq!(result.matches[0].keyword, "error");
assert_eq!(result.matches[0].before, vec!["INFO start"]);
assert_eq!(result.matches[0].after, vec!["INFO retrying"]);Structs§
- LogContext
Config - Configuration for
extract_context. - LogContext
Match - A single keyword match with surrounding context lines.
- LogContext
Result - Output of
extract_context.
Constants§
- DEFAULT_
CONTEXT_ LINES - Default lines of context captured before and after each match.
- DEFAULT_
KEYWORDS - Built-in keywords used when no custom list is provided.
- DEFAULT_
MAX_ MATCHES - Default cap on matches returned in a single result.
Functions§
- extract_
context - Scan
contentfor keyword matches and return surrounding context windows. - extract_
context_ reader - Streaming variant of
extract_contextfor large inputs.