Function parseSystemLogLine

  • Parses a single line of a system log into a structured SystemLogLine object.

    The function expects the log line to follow the format:

    YYYY-MM-DD HH:MM:SS.sss (uptime) [id]file:linelevel|message
    

    where the id part is optional.

    Returns

    A SystemLogLine object with parsed fields, or undefined if the line cannot be parsed.

    Example

    const line = '2025-12-05 10:01:23.123 (12:34:56) [device1]main.ts:123INFO|Started';
    const parsed = parseSystemLogLine(line);
    console.log(parsed?.date); // → Date object for '2025-12-05 10:01:23.123'
    console.log(parsed?.uptime); // → '12:34:56'
    console.log(parsed?.id); // → 'device1'
    console.log(parsed?.message); // → 'Started'

    Remarks

    • Uses a regular expression with the s (dotAll) flag; this may not be supported in all browsers.
    • If parsing fails, the function returns undefined.
    • The returned object includes the original line for reference.

    Parameters

    • line: string

      A single system log line as a string.

    Returns SystemLogLine | undefined

Generated using TypeDoc