# RequestLogger

<div class="jsdoc-content"><header>
    
        <h2><span class="attribs"><span class="type-signature"></span></span>
            <span class="ancestors"><a href="index.html">tracker</a>~</span>RequestLogger<span class="signature">(options)</span><span class="type-signature"></span></h2>
        
            <div class="class-description"><p>A request tracker that logs the requests executed through the session, according to a set of
configurable options.</p></div>
        
    
</header>


    
        

    
    </div>

## Constructor

<div class="jsdoc-content">
    

    
    <h4 class="name" id="RequestLogger"><span class="type-signature"></span>new RequestLogger<span class="signature">(options)</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    <p>Creates a new instance of RequestLogger.</p>
</div>









    <h5>Parameters:</h5>
    

<table class="params docutils align-default">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>options</code></td>
            

            <td class="type">
            
                
<span class="param-type">Object</span>


            
            </td>

            

            

            <td class="description last">
                <h6>Properties</h6>
                

<table class="params docutils align-default">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        
        <th>Attributes</th>
        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>slowThreshold</code></td>
            

            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            

            <td class="description last"><p>The threshold in milliseconds beyond which queries are considered 'slow'
and logged as such by the driver.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>requestSizeThreshold</code></td>
            

            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            

            <td class="description last"><p>The threshold in bytes beyond which requests are considered 'large'
and logged as such by the driver.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>logNormalRequests</code></td>
            

            <td class="type">
            
                
<span class="param-type">Boolean</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            

            <td class="description last"><p>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.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>logErroredRequests</code></td>
            

            <td class="type">
            
                
<span class="param-type">Boolean</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            

            <td class="description last"><p>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.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>messageMaxQueryLength</code></td>
            

            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            

            <td class="description last"><p>The maximum amount of characters that are logged from the query
portion of the message. Defaults to 500.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>messageMaxParameterValueLength</code></td>
            

            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            

            <td class="description last"><p>The maximum amount of characters of each query parameter
value that will be included in the message. Defaults to 50.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>messageMaxErrorStackTraceLength</code></td>
            

            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            

            <td class="description last"><p>The maximum amount of characters of the stack trace
that will be included in the message. Defaults to 200.</p></td>
        </tr>

    
    </tbody>
</table>

            </td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    
    <dt class="implements">Implements:</dt>
    <dd class="implements"><ul>
        
            <li><a href="RequestTracker.html">module:tracker~RequestTracker</a></li>
        
    </ul></dd>
    

    

    

    

    

    

    

    
    
    

    

    

    
</dl><div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/tracker/request-logger.js#L25" target="_blank" rel="noopener">tracker/request-logger.js, line 25</a></p></div>



















    <h5>Example</h5>
    
        <p class="code-caption">Logging slow queries</p>
    
    <div class="highlight-javascript notranslate"><div class="highlight"><pre>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 });</pre></div></div>



    
    

    

    

    

    

    

    

    
        </div>

## Members

<div class="jsdoc-content">

        
            
<h4 class="name" id="emitter"><span class="type-signature"></span>emitter<span class="type-signature"> :EventEmitter</span></h4>




<div class="description">
    <p>The object instance that emits <code>'slow'</code>, <code>'large'</code>, <code>'normal'</code> and
<code>'failure'</code> events.</p>
</div>



    <h5>Type:</h5>
    <ul>
        <li>
            
<span class="param-type">EventEmitter</span>


        </li>
    </ul>





<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/tracker/request-logger.js#L77" target="_blank" rel="noopener">tracker/request-logger.js, line 77</a></p></div>






        
            
<h4 class="name" id="logErroredRequests"><span class="type-signature"></span>logErroredRequests<span class="type-signature"> :Boolean</span></h4>




<div class="description">
    <p>Determines whether it should emit 'failure' events for every EXECUTE, QUERY and BATCH request execution that
resulted in an error</p>
</div>



    <h5>Type:</h5>
    <ul>
        <li>
            
<span class="param-type">Boolean</span>


        </li>
    </ul>





<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/tracker/request-logger.js#L70" target="_blank" rel="noopener">tracker/request-logger.js, line 70</a></p></div>






        
            
<h4 class="name" id="logNormalRequests"><span class="type-signature"></span>logNormalRequests<span class="type-signature"> :Boolean</span></h4>




<div class="description">
    <p>Determines whether it should emit 'normal' events for every EXECUTE, QUERY and BATCH request executed
successfully, useful only for debugging</p>
</div>



    <h5>Type:</h5>
    <ul>
        <li>
            
<span class="param-type">Boolean</span>


        </li>
    </ul>





<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/tracker/request-logger.js#L63" target="_blank" rel="noopener">tracker/request-logger.js, line 63</a></p></div>






        
    

    
        </div>

## Methods

<div class="jsdoc-content">

        
            

    

    
    <h4 class="name" id="onError"><span class="type-signature"></span>onError<span class="signature">(host, query, parameters, executionOptions, requestLength, err, latency)</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    <p>Logs message if request execution was too large and/or encountered an error.</p>
</div>









    <h5>Parameters:</h5>
    

<table class="params docutils align-default">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>host</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="Host.html">Host</a></span>


            
            </td>

            

            

            <td class="description last"><p>The node that acted as coordinator of the request.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>query</code></td>
            

            <td class="type">
            
                
<span class="param-type">String</span>
|

<span class="param-type">Array&lt;any></span>


            
            </td>

            

            

            <td class="description last"><p>In the case of prepared or unprepared query executions, the provided
query string. For batch requests, an Array containing the queries and parameters provided.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>parameters</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array&lt;any></span>
|

<span class="param-type">Object</span>
|

<span class="param-type">null</span>


            
            </td>

            

            

            <td class="description last"><p>In the case of prepared or unprepared query executions, the provided
parameters.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>executionOptions</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="../ExecutionOptions.html">ExecutionOptions</a></span>


            
            </td>

            

            

            <td class="description last"><p>The information related to the execution of the request.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>requestLength</code></td>
            

            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>

            

            

            <td class="description last"><p>Length of the body of the request. When the failure occurred before the request was
written to the wire, the length will be <code>0</code>.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>err</code></td>
            

            <td class="type">
            
                
<span class="param-type">Error</span>


            
            </td>

            

            

            <td class="description last"><p>The error that caused that caused the request to fail.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>latency</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array&lt;Number></span>


            
            </td>

            

            

            <td class="description last"><p>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 <code>process.hrtime()</code>).</p></td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    
    <dt class="implements">Implements:</dt>
    <dd class="implements"><ul>
        
            <li><a href="RequestTracker.html#onError">module:tracker~RequestTracker#onError</a></li>
        
    </ul></dd>
    

    

    

    

    

    

    

    
    
    

    

    

    
</dl><div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/tracker/request-logger.js#L136" target="_blank" rel="noopener">tracker/request-logger.js, line 136</a></p></div>




















        
            

    

    
    <h4 class="name" id="onSuccess"><span class="type-signature"></span>onSuccess<span class="signature">(host, query, parameters, executionOptions, requestLength, responseLength, latency)</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    <p>Logs message if request execution was deemed too slow, large or if normal requests are logged.</p>
</div>









    <h5>Parameters:</h5>
    

<table class="params docutils align-default">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>host</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="Host.html">Host</a></span>


            
            </td>

            

            

            <td class="description last"><p>The node that acted as coordinator of the request.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>query</code></td>
            

            <td class="type">
            
                
<span class="param-type">String</span>
|

<span class="param-type">Array&lt;any></span>


            
            </td>

            

            

            <td class="description last"><p>In the case of prepared or unprepared query executions, the provided
query string. For batch requests, an Array containing the queries and parameters provided.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>parameters</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array&lt;any></span>
|

<span class="param-type">Object</span>
|

<span class="param-type">null</span>


            
            </td>

            

            

            <td class="description last"><p>In the case of prepared or unprepared query executions, the provided
parameters.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>executionOptions</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="../ExecutionOptions.html">ExecutionOptions</a></span>


            
            </td>

            

            

            <td class="description last"><p>The information related to the execution of the request.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>requestLength</code></td>
            

            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>

            

            

            <td class="description last"><p>Length of the body of the request.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>responseLength</code></td>
            

            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>

            

            

            <td class="description last"><p>Length of the body of the response.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>latency</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array&lt;Number></span>


            
            </td>

            

            

            <td class="description last"><p>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 <code>process.hrtime()</code>).</p></td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    
    <dt class="implements">Implements:</dt>
    <dd class="implements"><ul>
        
            <li><a href="RequestTracker.html#onSuccess">module:tracker~RequestTracker#onSuccess</a></li>
        
    </ul></dd>
    

    

    

    

    

    

    

    
    
    

    

    

    
</dl><div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/tracker/request-logger.js#L84" target="_blank" rel="noopener">tracker/request-logger.js, line 84</a></p></div></div>
