Function diffSystemLogContents

  • Computes the difference between two system log contents by returning only the new lines added after the last known line from the old content.

    Returns

    A string containing only the new lines from newContent that come after the reference line from oldContent. If the reference line is not found, returns the entire newContent.

    Example

    const oldLog = 'line1\nline2\nline3';
    const newLog = 'line1\nline2\nline3\nline4\nline5';
    const diff = diffSystemLogContents(oldLog, newLog);
    console.log(diff); // → 'line4\nline5'

    Remarks

    • Useful for incremental log processing where only newly appended lines need to be handled.
    • Handles negative indexing for selecting the reference line from the end of oldContent.

    Parameters

    • oldContent: string

      The previous log content.

    • newContent: string

      The current log content.

    • lineSeparator: string = '\n'

      Optional string used to split lines (default: '\n').

    • lastLineIndex: number = -2

      Optional index of the line in oldContent to use as the reference point (default: -2, i.e., the second-to-last line).

    Returns string

Generated using TypeDoc