Function log

Allows writing to a DOM element in console.log style. Element grows in size, so use something like overflow-y: scroll on its parent

const l = log(`#dataStream`); // Assumes HTML element with id `dataStream` exists
l.log(`Hi`);
l.log(); // Displays a horizontal rule

const l = log(document.getElementById(`dataStream`), {
timestamp: true,
truncateEntries: 20
});
l.log(`Hi`);
l.error(`Some error`); // Adds class `error` to line

For logging high-throughput streams:

// Silently drop log if it was less than 5ms since the last
const l = log(`#dataStream`, { minIntervalMs: 5 });

// Only the last 100 entries are kept
const l = log(`#dataStream`, { capacity: 100 });
  • Parameters

    • domQueryOrElement: string | HTMLElement

      Element or id of element

    • opts: LogOpts = {}

    Returns Log