Retrieves all captured log entries.
Array of all captured log entries in chronological order.
Subscribes to log entry changes with a callback.
Function called with current entries on each update.
Unsubscribe function to remove the listener.
Adds a new log entry to the collection; processes format specifiers and maintains max buffer size.
The log severity level.
Arguments passed to the console method.
addEntry(level: LogLevel, args: unknown[]): void {
const timestamp = new Date().toISOString();
const [primary, ...rest] = args;
let message = "";
let details: string[] = [];
if (
typeof primary === "string" &&
/%[sdifoOc%]/.test(primary) &&
rest.length
) {
// apply format specifiers against the first N args; remaining args become details
const consumed = countPlaceholders(primary);
const consumedArgs = rest.slice(0, consumed);
message = applyFormat(primary, consumedArgs);
details = rest.slice(consumed).map(serializeArgument);
} else {
message =
primary === undefined && rest.length === 0
? ""
: serializeArgument(primary);
details = rest.map(serializeArgument);
}
const entry: LogEntry = {
id: generateLogId(),
level,
message,
details,
timestamp,
source: extractSourceFromStack(new Error(message).stack),
isDebug: inferIsDebug(level),
groupPath:
this.#groupStack.length > 0 ? [...this.#groupStack] : undefined,
groupDepth:
this.#groupStack.length > 0 ? this.#groupStack.length : undefined,
};
this.#entries = [...this.#entries, entry].slice(-MAX_LOG_ENTRIES);
this.#notify();
}
Captures console output in production builds for debugging and error reporting.
Maintains an in-memory buffer of log entries with subscriptions for real-time updates. Supports format string processing and sensitive data redaction. Tracks console group hierarchy to preserve structural information about grouped logs.
Source