Skip to main content

parse_line

Function parse_line 

Source
pub fn parse_line(line: &str) -> Option<LogEntry>
Expand description

Parse a single line of JSON log input.

Returns Some(LogEntry) if line is a non-empty JSON object, otherwise None. The caller is expected to iterate over an input source and discard None results (optionally incrementing a “lines skipped” counter — the CLI does exactly this in milestone 6).

§Behaviour

  • Empty or whitespace-only lines return None.
  • Lines that are not valid JSON return None.
  • Lines that are valid JSON but not objects (e.g. 42, "hi", [1,2]) return None, because logdive’s v1 scope restricts ingestion to structured JSON logs.
  • Within an object, keys matching LogEntry::KNOWN_KEYS populate the corresponding struct fields; all other keys go into LogEntry::fields.
  • For the known string-typed fields, non-string scalar values (numbers, booleans, null) are stringified so information is preserved. Object and array values for known fields are not coerced — instead they remain in fields under their original key, leaving the known field as None.