Class: RequestLogger

tracker~RequestLogger(options)

A request tracker that logs the requests executed through the session, according to a set of configurable options.

Constructor

new RequestLogger(options)

Creates a new instance of RequestLogger.

Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Description
slowThreshold Number <optional>

The threshold in milliseconds beyond which queries are considered 'slow' and logged as such by the driver.

requestSizeThreshold Number <optional>

The threshold in bytes beyond which requests are considered 'large' and logged as such by the driver.

logNormalRequests Boolean <optional>

Determines whether it should emit 'normal' events for every EXECUTE, QUERY and BATCH request executed successfully, useful only for debugging. This option can be modified after the client is connected using the property RequestLogger#logNormalRequests.

logErroredRequests Boolean <optional>

Determines whether it should emit 'failure' events for every EXECUTE, QUERY and BATCH request execution that resulted in an error. This option can be modified after the client is connected using the property RequestLogger#logErroredRequests.

messageMaxQueryLength Number <optional>

The maximum amount of characters that are logged from the query portion of the message. Defaults to 500.

messageMaxParameterValueLength Number <optional>

The maximum amount of characters of each query parameter value that will be included in the message. Defaults to 50.

messageMaxErrorStackTraceLength Number <optional>

The maximum amount of characters of the stack trace that will be included in the message. Defaults to 200.

Implements:
Source:
Example

Logging slow queries

const requestLogger = new RequestLogger({ slowThreshold: 1000 });
requestLogger.emitter.on('show', message => console.log(message));
// Add the requestLogger to the client options
const client = new Client({ contactPoints, requestTracker: requestLogger });

Members

emitter :EventEmitter

The object instance that emits 'slow', 'large', 'normal' and 'failure' events.

Type:
  • EventEmitter
Source:

logErroredRequests :Boolean

Determines whether it should emit 'failure' events for every EXECUTE, QUERY and BATCH request execution that resulted in an error

Type:
  • Boolean
Source:

logNormalRequests :Boolean

Determines whether it should emit 'normal' events for every EXECUTE, QUERY and BATCH request executed successfully, useful only for debugging

Type:
  • Boolean
Source:

Methods

onError(host, query, parameters, executionOptions, requestLength, err, latency)

Logs message if request execution was too large and/or encountered an error.

Parameters:
Name Type Description
host Host

The node that acted as coordinator of the request.

query String | Array

In the case of prepared or unprepared query executions, the provided query string. For batch requests, an Array containing the queries and parameters provided.

parameters Array | Object | null

In the case of prepared or unprepared query executions, the provided parameters.

executionOptions ExecutionOptions

The information related to the execution of the request.

requestLength Number

Length of the body of the request. When the failure occurred before the request was written to the wire, the length will be 0.

err Error

The error that caused that caused the request to fail.

latency Array.<Number>

An array containing [seconds, nanoseconds] tuple, where nanoseconds is the remaining part of the real time that can't be represented in second precision (see process.hrtime()).

Implements:
Source:

onSuccess(host, query, parameters, executionOptions, requestLength, responseLength, latency)

Logs message if request execution was deemed too slow, large or if normal requests are logged.

Parameters:
Name Type Description
host Host

The node that acted as coordinator of the request.

query String | Array

In the case of prepared or unprepared query executions, the provided query string. For batch requests, an Array containing the queries and parameters provided.

parameters Array | Object | null

In the case of prepared or unprepared query executions, the provided parameters.

executionOptions ExecutionOptions

The information related to the execution of the request.

requestLength Number

Length of the body of the request.

responseLength Number

Length of the body of the response.

latency Array.<Number>

An array containing [seconds, nanoseconds] tuple, where nanoseconds is the remaining part of the real time that can't be represented in second precision (see process.hrtime()).

Implements:
Source: