Overview
TheLogData interface represents the complete log data object for an HTTP request-response cycle. It contains all information about the request, response, timing, size metrics, and optional enrichment data like IP geolocation and error details.
Interface Definition
Properties
Required Properties
The HTTP method used for the request.Example:
"GET", "POST", "PUT", "DELETE"The full URL path of the request, including query string.Example:
"/api/users/123?include=profile"The HTTP status code returned in the response.Example:
200, 404, 500Time taken for the complete request-response cycle, measured in milliseconds.Example:
145.23Size of the request body in bytes.Example:
1024Size of the response body in bytes.Example:
2048Object containing ISO string timestamps for request start and response end times. See Timestamp for details.Example:
Request headers as a key-value object. Headers excluded via
excludedHeaders option will not be present.Example:Query parameters from the request URL as a key-value object. Empty if
logQueryParams is disabled.Example:Optional Properties
The request body. Only present when
logBody option is enabled.Example:The response body. Only present when
logResponse option is enabled.Example:IP geolocation information. Only present when
getIpInfo function is provided in options. See IpInfo for details.Example:The User-Agent header from the request.Example:
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"The Referer header from the request.Example:
"https://example.com/dashboard"The Content-Type header from the request.Example:
"application/json", "multipart/form-data"The Content-Type header from the response.Example:
"application/json", "text/html"The HTTP protocol version used for the request.Example:
"1.1", "2.0"Request ID from headers (e.g.,
x-request-id) or auto-generated if autoGenerateRequestId option is enabled.Example: "550e8400-e29b-41d4-a716-446655440000"Hostname of the server handling the request.Example:
"api.example.com"The log level for this request:
'info', 'warn', or 'error'. Determined by customLogLevel function or default logic. See LogLevel for details.Example: "info"Usage Examples
Using LogData in onLog Callback
Custom Log Level Based on LogData
Custom Formatter for LogData
Sending LogData to External Service
Complete Example
See Also
- ApiLoggerOptions - Middleware configuration options
- Timestamp - Request/response timestamp structure
- IpInfo - IP geolocation information
- LogError - Error information structure
- LogLevel - Available log levels