Skip to main content

Module log_context

Module log_context 

Source
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§

LogContextConfig
Configuration for extract_context.
LogContextMatch
A single keyword match with surrounding context lines.
LogContextResult
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 content for keyword matches and return surrounding context windows.
extract_context_reader
Streaming variant of extract_context for large inputs.