Skip to main content

RequestLog

@webda/debug


Class: RequestLog

Defined in: debug/src/requestlog.ts:78

A fixed-size ring buffer that tracks HTTP requests and pushes lifecycle events to subscribers.

When the buffer is full, the oldest entry is evicted to make room for the new one.

Constructors​

Constructor​

new RequestLog(maxSize?): RequestLog

Defined in: debug/src/requestlog.ts:88

Creates a new RequestLog.

Parameters​

maxSize?​

number = 1000

Maximum number of entries to retain before evicting the oldest. Defaults to 1000.

Returns​

RequestLog

Methods​

attachDetails()​

attachDetails(id, details): void

Defined in: debug/src/requestlog.ts:153

Attach captured headers, bodies, and/or error details to an existing entry.

Merges the provided fields onto the entry. Does nothing (silently) if the id is unknown — the caller should call this only after startRequest.

Parameters​

id​

string

Unique identifier of the request.

details​

RequestLogDetails

Captured details to attach.

Returns​

void


completeRequest()​

completeRequest(id, statusCode, duration): void

Defined in: debug/src/requestlog.ts:121

Records the completion of a previously started request.

Updates the entry with the final status code and duration, then pushes a "result" event to all subscribers. Does nothing if the id is unknown.

Parameters​

id​

string

Unique identifier of the request.

statusCode​

number

HTTP response status code.

duration​

number

Request duration in milliseconds.

Returns​

void


getEntries()​

getEntries(): RequestLogEntry[]

Defined in: debug/src/requestlog.ts:170

Returns a shallow copy of all currently stored entries in insertion order.

Includes any captured headers, bodies, and error details.

Returns​

RequestLogEntry[]

Array of RequestLogEntry objects.


getEntry()​

getEntry(id): RequestLogEntry | undefined

Defined in: debug/src/requestlog.ts:198

Look up a single entry by id.

Parameters​

id​

string

Unique identifier of the request.

Returns​

RequestLogEntry | undefined

The entry, or undefined if not found.


getSummaries()​

getSummaries(): RequestLogSummary[]

Defined in: debug/src/requestlog.ts:181

Returns lightweight summaries of all stored entries — no headers or bodies.

Use this for the list view; use getEntry when the user drills in.

Returns​

RequestLogSummary[]

Array of RequestLogSummary objects in insertion order.


markNotFound()​

markNotFound(id): void

Defined in: debug/src/requestlog.ts:137

Marks a previously started request as a 404 Not Found response.

Updates the entry's status code to 404 and pushes a "404" event to all subscribers. Does nothing if the id is unknown.

Parameters​

id​

string

Unique identifier of the request.

Returns​

void


onEvent()​

onEvent(callback): () => void

Defined in: debug/src/requestlog.ts:208

Registers a callback that will be invoked for every future log event.

Parameters​

callback​

EventCallback

Function called with each RequestLogEvent.

Returns​

An unsubscribe function. Call it to stop receiving events.

() => void


startRequest()​

startRequest(id, method, url): void

Defined in: debug/src/requestlog.ts:100

Records the start of an incoming HTTP request.

If the buffer is at capacity the oldest entry is removed first. A "request" event is pushed to all subscribers.

Parameters​

id​

string

Unique identifier for the request.

method​

string

HTTP method (e.g. "GET", "POST").

url​

string

Request URL.

Returns​

void