Interface
Core Fields
method
The HTTP method of the request (e.g.,
GET, POST, PUT, DELETE, PATCH).url
The complete URL path including query parameters. This is the
originalUrl from Express, or url if originalUrl is not available.statusCode
The HTTP status code of the response (e.g.,
200, 404, 500).timeTaken
Time taken for the complete request-response cycle, measured in milliseconds with high precision using
process.hrtime().requestSize
Size of the request body in bytes. Calculated from the stringified request body or
Content-Length header.responseSize
Size of the response body in bytes. Calculated from the stringified response body.
timestamp
Object containing ISO 8601 formatted timestamps for request start and response completion.
headers
Request headers object. Headers specified in
excludedHeaders option are filtered out. Header values can be strings or string arrays.queryParams
Query parameters from the URL. Included only if
logQueryParams option is true (default).Optional Fields
body
Request body content. Included only if
logBody option is true (default). Can be any valid JSON type.Fields specified in maskFields option will have their values replaced with "***MASKED***".responseBody
Response body content. Included only if
logResponse option is true (default). Can be any valid JSON type.Fields specified in maskFields option will have their values replaced with "***MASKED***".ipInfo
IP address information returned by the
getIpInfo option function. Contains geolocation and other IP-related data.error
Error information if an error occurred during request processing. Captured from middleware errors or response errors.
userAgent
The
User-Agent header value from the request, providing information about the client application or browser.referer
The
Referer header value from the request, indicating the URL that referred to this request.requestContentType
The
Content-Type header of the request, indicating the media type of the request body.responseContentType
The
Content-Type header of the response, indicating the media type of the response body.httpVersion
The HTTP protocol version used for the request (e.g.,
1.0, 1.1, 2.0).requestId
Request ID from the
X-Request-ID header or auto-generated if autoGenerateRequestId option is enabled.Useful for distributed tracing and correlating logs across services.hostname
The hostname of the server handling the request, from
req.hostname or Host header.logLevel
The log level for this request, determining which console method is used (
console.log, console.warn, or console.error).Set by customLogLevel option or determined automatically:'error'if error is present'warn'if status code >= 400'info'otherwise
Complete Example
Successful Request
Failed Request with Error
Server Error
Usage
TheLogData structure is:
- Generated automatically by the logger middleware for each request
- Passed to the
onLogcallback if provided in options - Passed to
customLogLevelfor determining log level - Passed to
customFormatterfor custom formatting - Logged to console as JSON (unless custom formatter returns different format)
Accessing in onLog Callback
Using in Custom Formatter
See Also
- logger - Main logger function documentation
- ApiLoggerOptions - Configuration options reference